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>
This commit is contained in:
parent
4db7dbdb4a
commit
5b34ba414d
15
builtin/am.c
15
builtin/am.c
@ -1351,19 +1351,16 @@ static int get_mail_commit_oid(struct object_id *commit_id, const char *mail)
|
|||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
FILE *fp = xfopen(mail, "r");
|
FILE *fp = xfopen(mail, "r");
|
||||||
const char *x;
|
const char *x;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (strbuf_getline_lf(&sb, fp))
|
if (strbuf_getline_lf(&sb, fp) ||
|
||||||
return -1;
|
!skip_prefix(sb.buf, "From ", &x) ||
|
||||||
|
get_oid_hex(x, commit_id) < 0)
|
||||||
if (!skip_prefix(sb.buf, "From ", &x))
|
ret = -1;
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (get_oid_hex(x, commit_id) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user