Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
get_mail_commit_oid(): avoid resource leak
author
Johannes Schindelin
<johannes.schindelin@gmx.de>
Thu, 4 May 2017 13:55:45 +0000
(15:55 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Mon, 8 May 2017 03:18:19 +0000
(12:18 +0900)
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>
builtin/am.c
patch
|
blob
|
history
raw
|
patch
| inline |
side by side
(parent:
4db7dbd
)
diff --git
a/builtin/am.c
b/builtin/am.c
index a95dd8b4e6c793d9e51658e2ccbe535cf5a5af45..9c5c2c778e28dc5bc2bfc3e5a1cf32c247ed273f 100644
(file)
--- 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
;
}
/**