am: release strbuf on error return in hg_patch_to_mail()

Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Rene Scharfe committed Aug 30, 2017 at 19:49 UTC b36474ff6b4c7d0a4939b7551c576ef3de7e4719
1 file changed +19 -10
builtin/am.c
+19 -10
@@ -881,6 +881,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
881 static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)
882 {
883 struct strbuf sb = STRBUF_INIT;
884 + int rc = 0;
885
886 while (!strbuf_getline_lf(&sb, in)) {
887 const char *str;
@@ -894,19 +895,27 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)
895
896 errno = 0;
897 timestamp = parse_timestamp(str, &end, 10);
897 - if (errno)
898 - return error(_("invalid timestamp"));
898 + if (errno) {
899 + rc = error(_("invalid timestamp"));
900 + goto exit;
901 + }
902
900 - if (!skip_prefix(end, " ", &str))
901 - return error(_("invalid Date line"));
903 + if (!skip_prefix(end, " ", &str)) {
904 + rc = error(_("invalid Date line"));
905 + goto exit;
906 + }
907
908 errno = 0;
909 tz = strtol(str, &end, 10);
905 - if (errno)
906 - return error(_("invalid timezone offset"));
910 + if (errno) {
911 + rc = error(_("invalid timezone offset"));
912 + goto exit;
913 + }
914
908 - if (*end)
909 - return error(_("invalid Date line"));
915 + if (*end) {
916 + rc = error(_("invalid Date line"));
917 + goto exit;
918 + }
919
920 /*
921 * 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)
940 fwrite(sb.buf, 1, sb.len, out);
941 strbuf_reset(&sb);
942 }
934 -
943 +exit:
944 strbuf_release(&sb);
936 - return 0;
945 + return rc;
946 }
947
948 /**