Skip to content

Commit 39765e5

Browse files
committed
interpret_nth_last_branch(): plug small memleak
Signed-off-by: Junio C Hamano <[email protected]>
1 parent c829774 commit 39765e5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sha1_name.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
754754
int interpret_nth_last_branch(const char *name, struct strbuf *buf)
755755
{
756756
long nth;
757-
int i;
757+
int i, retval;
758758
struct grab_nth_branch_switch_cbdata cb;
759759
const char *brace;
760760
char *num_end;
@@ -774,17 +774,21 @@ int interpret_nth_last_branch(const char *name, struct strbuf *buf)
774774
for (i = 0; i < nth; i++)
775775
strbuf_init(&cb.buf[i], 20);
776776
cb.cnt = 0;
777+
retval = 0;
777778
for_each_reflog_ent("HEAD", grab_nth_branch_switch, &cb);
778779
if (cb.cnt < nth)
779-
return 0;
780+
goto release_return;
780781
i = cb.cnt % nth;
781782
strbuf_reset(buf);
782783
strbuf_add(buf, cb.buf[i].buf, cb.buf[i].len);
784+
retval = brace-name+1;
785+
786+
release_return:
783787
for (i = 0; i < nth; i++)
784788
strbuf_release(&cb.buf[i]);
785789
free(cb.buf);
786790

787-
return brace-name+1;
791+
return retval;
788792
}
789793

790794
/*

0 commit comments

Comments
 (0)