Skip to content

Commit 5b34ba4

Browse files
dschogitster
authored andcommitted
get_mail_commit_oid(): avoid resource leak
When we fail to read, or parse, the file, we still want to close the file descriptor and release the strbuf. Reported via Coverity. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4db7dbd commit 5b34ba4

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

builtin/am.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,19 +1351,16 @@ static int get_mail_commit_oid(struct object_id *commit_id, const char *mail)
13511351
struct strbuf sb = STRBUF_INIT;
13521352
FILE *fp = xfopen(mail, "r");
13531353
const char *x;
1354+
int ret = 0;
13541355

1355-
if (strbuf_getline_lf(&sb, fp))
1356-
return -1;
1357-
1358-
if (!skip_prefix(sb.buf, "From ", &x))
1359-
return -1;
1360-
1361-
if (get_oid_hex(x, commit_id) < 0)
1362-
return -1;
1356+
if (strbuf_getline_lf(&sb, fp) ||
1357+
!skip_prefix(sb.buf, "From ", &x) ||
1358+
get_oid_hex(x, commit_id) < 0)
1359+
ret = -1;
13631360

13641361
strbuf_release(&sb);
13651362
fclose(fp);
1366-
return 0;
1363+
return ret;
13671364
}
13681365

13691366
/**

0 commit comments

Comments
 (0)