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>
Johannes Schindelin committed
May 4, 2017 at 15:55 UTC
5b34ba414d105a8219e55babd0780a935a0c0c20
1 file changed
+6
-9
builtin/am.c
+6
-9
@@ -1351,19 +1351,16 @@ static int get_mail_commit_oid(struct object_id *commit_id, const char *mail)
1351
struct strbuf sb = STRBUF_INIT;
1352
FILE *fp = xfopen(mail, "r");
1353
const char *x;
1354
+ int ret = 0;
1355
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;
1360
1361
strbuf_release(&sb);
1362
fclose(fp);
1366
- return 0;
1363
+ return ret;
1364
}
1365
1366
/**