From b36474ff6b4c7d0a4939b7551c576ef3de7e4719 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Wed, 30 Aug 2017 19:49:33 +0200 Subject: [PATCH] am: release strbuf on error return in hg_patch_to_mail() Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin/am.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 3c50b03faa..3d38b3fe9f 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -881,6 +881,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths, static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr) { struct strbuf sb = STRBUF_INIT; + int rc = 0; while (!strbuf_getline_lf(&sb, in)) { const char *str; @@ -894,19 +895,27 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr) errno = 0; timestamp = parse_timestamp(str, &end, 10); - if (errno) - return error(_("invalid timestamp")); + if (errno) { + rc = error(_("invalid timestamp")); + goto exit; + } - if (!skip_prefix(end, " ", &str)) - return error(_("invalid Date line")); + if (!skip_prefix(end, " ", &str)) { + rc = error(_("invalid Date line")); + goto exit; + } errno = 0; tz = strtol(str, &end, 10); - if (errno) - return error(_("invalid timezone offset")); + if (errno) { + rc = error(_("invalid timezone offset")); + goto exit; + } - if (*end) - return error(_("invalid Date line")); + if (*end) { + rc = error(_("invalid Date line")); + goto exit; + } /* * mercurial's timezone is in seconds west of UTC, @@ -931,9 +940,9 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr) fwrite(sb.buf, 1, sb.len, out); strbuf_reset(&sb); } - +exit: strbuf_release(&sb); - return 0; + return rc; } /** -- 2.47.1