summaryrefslogtreecommitdiff
path: root/builtin/am.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2017-05-04 15:55:45 +0200
committerJunio C Hamano <gitster@pobox.com>2017-05-08 12:18:19 +0900
commit5b34ba414d105a8219e55babd0780a935a0c0c20 (patch)
treec79fef57bcaef2e07ea1a37a1f3fa2266d85d196 /builtin/am.c
parent4db7dbdb4ae5426ab133b3844ea2a6889c6897d7 (diff)
downloadgit-5b34ba414d105a8219e55babd0780a935a0c0c20.tar.gz
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>
Diffstat (limited to 'builtin/am.c')
-rw-r--r--builtin/am.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/builtin/am.c b/builtin/am.c
index a95dd8b4e6..9c5c2c778e 100644
--- a/builtin/am.c
+++ b/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;
FILE *fp = xfopen(mail, "r");
const char *x;
+ int ret = 0;
- if (strbuf_getline_lf(&sb, fp))
- return -1;
-
- if (!skip_prefix(sb.buf, "From ", &x))
- return -1;
-
- if (get_oid_hex(x, commit_id) < 0)
- return -1;
+ if (strbuf_getline_lf(&sb, fp) ||
+ !skip_prefix(sb.buf, "From ", &x) ||
+ get_oid_hex(x, commit_id) < 0)
+ ret = -1;
strbuf_release(&sb);
fclose(fp);
- return 0;
+ return ret;
}
/**