]> diplodocus.org Git - nmh/commitdiff
mhbuildsbr.c: Ensure temporary FILE closed regardless of success.
authorRalph Corderoy <ralph@inputplus.co.uk>
Wed, 23 Aug 2017 22:38:50 +0000 (23:38 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Wed, 23 Aug 2017 22:38:50 +0000 (23:38 +0100)
If the fopen() succeeded, but the fwrite() failed, then the FILE wasn't
fclose()'d.

uip/mhbuildsbr.c

index 1b0b327b3485f3722b13aefb5371275218f9fa3b..7c957b08198c127750c1999cf8a86335c34b48ff 100644 (file)
@@ -2380,7 +2380,7 @@ extract_headers (CT ct, char *reply_file, FILE **reply_fp) {
         CT tmp_ct;
         char *tmp_file;
         FILE *tmp_f;
         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';
 
         /* 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");
            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;
             goto failed_to_extract_ct;
-        fclose (tmp_f);
 
         tmp_ct = parse_mime (tmp_file);
         if (tmp_ct) {
 
         tmp_ct = parse_mime (tmp_file);
         if (tmp_ct) {