From: Ralph Corderoy Date: Wed, 23 Aug 2017 22:38:50 +0000 (+0100) Subject: mhbuildsbr.c: Ensure temporary FILE closed regardless of success. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/aad7213c7ebca96dff5f141e0e26a165eba4e6b8?ds=sidebyside;hp=2b60a54adb3b0bf5a9b927708085492b816a6015 mhbuildsbr.c: Ensure temporary FILE closed regardless of success. If the fopen() succeeded, but the fwrite() failed, then the FILE wasn't fclose()'d. --- diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index 1b0b327b..7c957b08 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -2380,7 +2380,7 @@ extract_headers (CT ct, char *reply_file, FILE **reply_fp) { CT tmp_ct; char *tmp_file; FILE *tmp_f; - size_t n; + size_t n, written; /* Truncate buffer to just the C-T. */ *end_of_header = '\0'; @@ -2395,9 +2395,12 @@ extract_headers (CT ct, char *reply_file, FILE **reply_fp) { reply, which we'll use below. */ tmp_file = getcpy (m_mktemp2 (NULL, invo_name, NULL, NULL)); tmp_f = fopen(tmp_file, "w"); - if (!tmp_f || fwrite(buffer, 1, n, tmp_f) != n) + if (!tmp_f) + goto failed_to_extract_ct; + written = fwrite(buffer, 1, n, tmp_f); + fclose(tmp_f); + if (written != n) goto failed_to_extract_ct; - fclose (tmp_f); tmp_ct = parse_mime (tmp_file); if (tmp_ct) {