From: Pierre Habouzit Date: Sat, 25 Nov 2006 00:32:52 +0000 (+0100) Subject: fclose -> m_fclose X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=9ed7a487e3a922f2cbb222961c2c9710c3a65f91 fclose -> m_fclose Signed-off-by: Pierre Habouzit --- diff --git a/alias.c b/alias.c index 6b13773..68afc25 100644 --- a/alias.c +++ b/alias.c @@ -300,7 +300,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr) buf[0] = '\0'; rfc822_write_address(buf, sizeof(buf), new->addr, 0); write_safe_address(rc, buf); - fclose(rc); + m_fclose(&rc); mutt_message _("Alias added."); } else { mutt_perror(buf); diff --git a/attach.c b/attach.c index 1d1ce66..4e6fff1 100644 --- a/attach.c +++ b/attach.c @@ -56,10 +56,8 @@ int mutt_get_tmp_attachment (BODY * a) else mutt_perror(fpin ? tempfile : a->filename); - if (fpin) - fclose (fpin); - if (fpout) - fclose (fpout); + m_fclose(&fpin); + m_fclose(&fpout); return a->unlink ? 0 : -1; } @@ -147,8 +145,8 @@ int mutt_compose_attachment (BODY * a) goto bailout; } mutt_copy_stream (fp, tfp); - fclose (fp); - fclose (tfp); + m_fclose(&fp); + m_fclose(&tfp); mutt_unlink (a->filename); if (mutt_rename_file (tempfile, a->filename) != 0) { mutt_perror (_("Failure to rename file.")); @@ -742,13 +740,12 @@ int mutt_save_attachment (FILE * fp, BODY * m, char *path, int flags, fseeko ((s.fpin = fp), m->offset, 0); mutt_decode_attachment (m, &s); - if (fclose (s.fpout) != 0) { + if (m_fclose(&s.fpout) != 0) { mutt_perror ("fclose"); return (-1); } } - } - else { + } else { /* In send mode, just copy file */ FILE *ofp, *nfp; @@ -809,7 +806,7 @@ int mutt_decode_save_attachment (FILE * fp, BODY * m, char *path, if (stat (m->filename, &st) == -1) { mutt_perror ("stat"); - fclose (s.fpout); + m_fclose(&s.fpout); return (-1); } @@ -838,7 +835,7 @@ int mutt_decode_save_attachment (FILE * fp, BODY * m, char *path, mutt_body_handler (m, &s); - fclose (s.fpout); + m_fclose(&s.fpout); if (fp == NULL) { m->length = 0; m->encoding = saved_encoding; @@ -847,7 +844,7 @@ int mutt_decode_save_attachment (FILE * fp, BODY * m, char *path, m->parts = saved_parts; m->hdr = saved_hdr; } - fclose (s.fpin); + m_fclose(&s.fpin); } return (0); @@ -1010,7 +1007,7 @@ int mutt_attach_check (HEADER* hdr) { p++; } } - fclose (fp); + m_fclose(&fp); return (found); } diff --git a/commands.c b/commands.c index e0dfe2e..d8a10d7 100644 --- a/commands.c +++ b/commands.c @@ -356,7 +356,7 @@ static int _mutt_pipe_message(HEADER * h, char *cmd, int decode, int print, } pipe_msg (h, fpout, decode, print); - fclose (fpout); + m_fclose(&fpout); rc = mutt_wait_filter (thepid); } else { /* handle tagged messages */ diff --git a/compose.c b/compose.c index c1a0de4..8a8d0c5 100644 --- a/compose.c +++ b/compose.c @@ -1165,7 +1165,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ p_delete(&idx[idxlen]); continue; } - fclose (fp); + m_fclose(&fp); if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) { mutt_error diff --git a/copy.c b/copy.c index c63ab8d..d386400 100644 --- a/copy.c +++ b/copy.c @@ -616,12 +616,12 @@ _mutt_copy_message (FILE * fpout, FILE * fpin, HEADER * hdr, BODY * body, fseeko (fp, cur->offset, 0); if (mutt_copy_bytes (fp, fpout, cur->length) == -1) { - fclose (fp); + m_fclose(&fp); body_list_wipe(&cur); return (-1); } body_list_wipe(&cur); - fclose (fp); + m_fclose(&fp); } else { fseeko (fpin, body->offset, 0); diff --git a/editmsg.c b/editmsg.c index c77cbf9..6d848e3 100644 --- a/editmsg.c +++ b/editmsg.c @@ -165,8 +165,7 @@ static int edit_one_message (CONTEXT * ctx, HEADER * cur) mx_close_mailbox (&tmpctx, NULL); bail: - if (fp) - fclose (fp); + m_fclose(&fp); if (rc >= 0) unlink (tmp); diff --git a/handler.c b/handler.c index 0f37639..59c70de 100644 --- a/handler.c +++ b/handler.c @@ -1415,7 +1415,7 @@ int mutt_body_handler (BODY * b, STATE * s) if (decode) { b->length = ftello (s->fpout); b->offset = 0; - fclose (s->fpout); + m_fclose(&s->fpout); /* restore final destination and substitute the tempfile for input */ s->fpout = fp; @@ -1439,7 +1439,7 @@ int mutt_body_handler (BODY * b, STATE * s) b->offset = tmpoffset; /* restore the original source stream */ - fclose (s->fpin); + m_fclose(&s->fpin); s->fpin = fp; } } diff --git a/headers.c b/headers.c index f158c12..8b69cc5 100644 --- a/headers.c +++ b/headers.c @@ -47,8 +47,8 @@ void mutt_edit_headers (const char *editor, mutt_copy_stream (ifp, ofp); - fclose (ifp); - fclose (ofp); + m_fclose(&ifp); + m_fclose(&ofp); if (stat (path, &st) == -1) { mutt_perror (path); @@ -76,7 +76,7 @@ void mutt_edit_headers (const char *editor, if ((ofp = safe_fopen (body, "w")) == NULL) { /* intentionally leak a possible temporary file here */ - fclose (ifp); + m_fclose(&ifp); mutt_perror (body); return; } @@ -84,8 +84,8 @@ void mutt_edit_headers (const char *editor, n = mutt_read_rfc822_header (ifp, NULL, 1, 0); while ((i = fread (buffer, 1, sizeof (buffer), ifp)) > 0) fwrite (buffer, 1, i, ofp); - fclose (ofp); - fclose (ifp); + m_fclose(&ofp); + m_fclose(&ifp); mutt_unlink (path); /* restore old info. */ diff --git a/help.c b/help.c index 584e80b..407b7a4 100644 --- a/help.c +++ b/help.c @@ -303,7 +303,7 @@ void mutt_help (int menu) if (menu != MENU_PAGER) dump_unbound (f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]); - fclose(f); + m_fclose(&f); snprintf(buf, sizeof (buf), _("Help for %s"), desc); } while (mutt_do_pager(buf, tmp, diff --git a/imap/message.c b/imap/message.c index 1ea30c9..a2debe7 100644 --- a/imap/message.c +++ b/imap/message.c @@ -163,7 +163,7 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) if ((mfhrc < -1) || ((rc != IMAP_CMD_CONTINUE) && (rc != IMAP_CMD_OK))) { imap_free_header_data((void *)&h.data); - fclose (fp); + m_fclose(&fp); mutt_hcache_close (hc); return -1; } @@ -262,7 +262,7 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) if ((mfhrc < -1) || ((rc != IMAP_CMD_CONTINUE) && (rc != IMAP_CMD_OK))) { imap_free_header_data ((void *)&h.data); - fclose (fp); + m_fclose(&fp); #ifdef USE_HCACHE mutt_hcache_close (hc); #endif /* USE_HCACHE */ @@ -283,7 +283,7 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) mutt_hcache_close (hc); #endif /* USE_HCACHE */ - fclose (fp); + m_fclose(&fp); if (ctx->msgcount > oldmsgcount) mx_update_context (ctx, ctx->msgcount - oldmsgcount); @@ -574,7 +574,7 @@ int imap_append_message (CONTEXT * ctx, MESSAGE * msg) pc = imap_next_word (pc); mutt_error ("%s", pc); mutt_sleep (1); - fclose (fp); + m_fclose(&fp); goto fail; } @@ -595,7 +595,7 @@ int imap_append_message (CONTEXT * ctx, MESSAGE * msg) flush_buffer (buf, &len, idata->conn); mutt_socket_write (idata->conn, "\r\n"); - fclose (fp); + m_fclose(&fp); do rc = imap_cmd_step (idata); diff --git a/init.c b/init.c index d4b367c..5bc6d04 100644 --- a/init.c +++ b/init.c @@ -1995,7 +1995,7 @@ static int source_rc (const char *rcfile, BUFFER * err) } p_delete(&token.data); p_delete(&linebuf); - fclose (f); + m_fclose(&f); if (pid != -1) mutt_wait_filter (pid); if (rc) { @@ -2524,7 +2524,7 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) q++; *q = '\0'; NewsServer = m_strdup(p); - fclose (f); + m_fclose(&f); } } if ((p = getenv ("NNTPSERVER"))) diff --git a/lib-crypt/crypt-gpgme.c b/lib-crypt/crypt-gpgme.c index b3304f5..29a676e 100644 --- a/lib-crypt/crypt-gpgme.c +++ b/lib-crypt/crypt-gpgme.c @@ -379,13 +379,11 @@ static gpgme_data_t body_to_data_object (BODY * a, int convert) buf[0] = c; gpgme_data_write (data, buf, 1); } - fclose (fptmp); gpgme_data_seek (data, 0, SEEK_SET); - } - else { - fclose (fptmp); + } else { err = gpgme_data_new_from_file (&data, tempfile, 1); } + m_fclose(&fptmp); unlink (tempfile); if (err) { mutt_error (_("error allocating data object: %s\n"), gpgme_strerror (err)); @@ -470,7 +468,7 @@ static char *data_object_to_tempfile (gpgme_data_t data, FILE ** ret_fp) while ((nread = gpgme_data_read (data, buf, sizeof (buf)))) { if (fwrite (buf, nread, 1, fp) != 1) { mutt_perror (tempfile); - fclose (fp); + m_fclose(&fp); unlink (tempfile); return NULL; } @@ -479,11 +477,11 @@ static char *data_object_to_tempfile (gpgme_data_t data, FILE ** ret_fp) if (ret_fp) rewind (fp); else - fclose (fp); + m_fclose(&fp); if (nread == -1) { mutt_error (_("error reading data object: %s\n"), gpgme_strerror (err)); unlink (tempfile); - fclose (fp); + m_fclose(&fp); return NULL; } if (ret_fp) @@ -1542,7 +1540,7 @@ int smime_gpgme_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, b->type = saved_b_type; b->length = saved_b_length; b->offset = saved_b_offset; - fclose (tmpfp); + m_fclose(&tmpfp); rewind (*fpout); if (*cur && !is_signed && !(*cur)->parts && mutt_is_application_smime (*cur)) { @@ -1577,7 +1575,7 @@ int smime_gpgme_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, bb->length = ftello (s.fpout); bb->offset = 0; rewind (tmpfp); - fclose (*fpout); + m_fclose(&*fpout); p_clear(&s, 1); s.fpin = tmpfp; @@ -1595,7 +1593,7 @@ int smime_gpgme_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, bb->type = saved_b_type; bb->length = saved_b_length; bb->offset = saved_b_offset; - fclose (tmpfp); + m_fclose(&tmpfp); rewind (*fpout); body_list_wipe(cur); *cur = tmp_b; @@ -1736,7 +1734,7 @@ static void copy_clearsigned (gpgme_data_t data, STATE * s, char *charset) } fgetconv_close (&fc); - fclose (fp); + m_fclose(&fp); } @@ -2038,7 +2036,7 @@ int pgp_gpgme_encrypted_handler (BODY * a, STATE * s) body_list_wipe(&tattach); } - fclose (fpout); + m_fclose(&fpout); mutt_unlink (tempfile); return (rc); } @@ -2102,7 +2100,7 @@ int smime_gpgme_application_handler (BODY * a, STATE * s) body_list_wipe(&tattach); } - fclose (fpout); + m_fclose(&fpout); mutt_unlink (tempfile); return (rc); } @@ -2969,7 +2967,7 @@ static void verify_key (crypt_key_t * key) leave: gpgme_key_release (k); gpgme_release (listctx); - fclose (fp); + m_fclose(&fp); mutt_clear_error (); snprintf (cmd, sizeof (cmd), _("Key ID: 0x%s"), crypt_keyid (key)); mutt_do_pager (cmd, tempfile, 0, NULL); diff --git a/lib-crypt/crypt.c b/lib-crypt/crypt.c index 87c1b41..dd2eb02 100644 --- a/lib-crypt/crypt.c +++ b/lib-crypt/crypt.c @@ -349,7 +349,7 @@ void crypt_extract_keys_from_messages (HEADER * h) if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT && !crypt_valid_passphrase (Context->hdrs[Context->v2r[i]]-> security)) { - fclose (fpout); + m_fclose(&fpout); break; } @@ -420,7 +420,7 @@ void crypt_extract_keys_from_messages (HEADER * h) } } - fclose (fpout); + m_fclose(&fpout); if (isendwin ()) mutt_any_key_to_continue (NULL); diff --git a/lib-crypt/gnupgparse.c b/lib-crypt/gnupgparse.c index d4876d6..a2d8549 100644 --- a/lib-crypt/gnupgparse.c +++ b/lib-crypt/gnupgparse.c @@ -310,7 +310,7 @@ pgp_key_t pgp_get_candidates (pgp_ring_t keyring, string_list_t * hints) if (ferror (fp)) mutt_perror ("fgets"); - fclose (fp); + m_fclose(&fp); mutt_wait_filter (thepid); close (devnull); diff --git a/lib-crypt/pgp.c b/lib-crypt/pgp.c index 85725d7..ea63f2c 100644 --- a/lib-crypt/pgp.c +++ b/lib-crypt/pgp.c @@ -545,7 +545,7 @@ int pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) fseeko (s->fpin, sigbdy->offset, 0); mutt_copy_bytes (s->fpin, fp, sigbdy->length); - fclose (fp); + m_fclose(&fp); pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL); if (pgperr == NULL) { @@ -606,7 +606,7 @@ static void pgp_extract_keys_from_attachment (FILE * fp, BODY * top) mutt_body_handler (top, &s); - fclose (tempfp); + m_fclose(&tempfp); pgp_invoke_import (tempfname); mutt_any_key_to_continue (NULL); @@ -656,9 +656,9 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) unlink (pgperrfile); pgptmp = m_tempfile(pgptmpfile, sizeof(pgptmpfile), NONULL(Tempdir), NULL); - if (pgptmp == NULL) { + if (!pgptmp == NULL) { mutt_perror (pgptmpfile); - fclose (pgperr); + m_fclose(&pgperr); return NULL; } @@ -668,11 +668,11 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) fseeko (s->fpin, a->offset, 0); mutt_copy_bytes (s->fpin, pgptmp, a->length); - fclose (pgptmp); + m_fclose(&pgptmp); if ((thepid = pgp_invoke_decrypt (&pgpin, &pgpout, NULL, -1, -1, fileno (pgperr), pgptmpfile)) == -1) { - fclose (pgperr); + m_fclose(&pgperr); unlink (pgptmpfile); if (s->flags & M_DISPLAY) state_attach_puts (_ @@ -687,7 +687,7 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) if (!pgp_use_gpg_agent ()) fputs (PgpPass, pgpin); fputc ('\n', pgpin); - fclose (pgpin); + m_fclose(&pgpin); /* Read the output from PGP, and make sure to change CRLF to LF, otherwise * read_mime_header has a hard time parsing the message. @@ -699,7 +699,7 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) fputs (buf, fpout); } - fclose (pgpout); + m_fclose(&pgpout); rv = mutt_wait_filter (thepid); mutt_unlink (pgptmpfile); @@ -712,7 +712,7 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) p->goodsig = 0; state_attach_puts (_("[-- End of PGP output --]\n\n"), s); } - fclose (pgperr); + m_fclose(&pgperr); fflush (fpout); rewind (fpout); @@ -844,7 +844,7 @@ int pgp_encrypted_handler (BODY * a, STATE * s) rc = -1; } - fclose (fpout); + m_fclose(&fpout); mutt_unlink (tempfile); return (rc); @@ -875,7 +875,7 @@ BODY *pgp_sign_message (BODY * a) sfp = m_tempfile(signedfile, sizeof(signedfile), NONULL(Tempdir), NULL); if (sfp == NULL) { mutt_perror (signedfile); - fclose (fp); + m_fclose(&fp); unlink (sigfile); return NULL; } @@ -883,13 +883,13 @@ BODY *pgp_sign_message (BODY * a) mutt_write_mime_header (a, sfp); fputc ('\n', sfp); mutt_write_mime_body (a, sfp); - fclose (sfp); + m_fclose(&sfp); if ((thepid = pgp_invoke_sign (&pgpin, &pgpout, &pgperr, -1, -1, -1, signedfile)) == -1) { mutt_perror (_("Can't open PGP subprocess!")); - fclose (fp); + m_fclose(&fp); unlink (sigfile); unlink (signedfile); return NULL; @@ -898,7 +898,7 @@ BODY *pgp_sign_message (BODY * a) if (!pgp_use_gpg_agent ()) fputs (PgpPass, pgpin); fputc ('\n', pgpin); - fclose (pgpin); + m_fclose(&pgpin); /* * Read back the PGP signature. Also, change MESSAGE=>SIGNATURE as @@ -924,11 +924,11 @@ BODY *pgp_sign_message (BODY * a) if (mutt_wait_filter (thepid) && option (OPTPGPCHECKEXIT)) empty = 1; - fclose (pgperr); - fclose (pgpout); + m_fclose(&pgperr); + m_fclose(&pgpout); unlink (signedfile); - if (fclose (fp) != 0) { + if (m_fclose(&fp) != 0) { mutt_perror ("fclose"); unlink (sigfile); return (NULL); @@ -1122,7 +1122,7 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL); if (pgperr == NULL) { mutt_perror (pgperrfile); - fclose (fpout); + m_fclose(&fpout); unlink (tempfile); return NULL; } @@ -1131,9 +1131,9 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) fptmp = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(Tempdir), NULL); if (fptmp == NULL) { mutt_perror (pgpinfile); - fclose (fpout); + m_fclose(&fpout); unlink (tempfile); - fclose (pgperr); + m_fclose(&pgperr); unlink (pgperrfile); return NULL; } @@ -1144,12 +1144,12 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) mutt_write_mime_header (a, fptmp); fputc ('\n', fptmp); mutt_write_mime_body (a, fptmp); - fclose (fptmp); + m_fclose(&fptmp); if ((thepid = pgp_invoke_encrypt (&pgpin, NULL, NULL, -1, fileno (fpout), fileno (pgperr), pgpinfile, keylist, sign)) == -1) { - fclose (pgperr); + m_fclose(&pgperr); unlink (pgpinfile); return (NULL); } @@ -1159,7 +1159,7 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) fputs (PgpPass, pgpin); fputc ('\n', pgpin); } - fclose (pgpin); + m_fclose(&pgpin); if (mutt_wait_filter (thepid) && option (OPTPGPCHECKEXIT)) empty = 1; @@ -1170,7 +1170,7 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) rewind (fpout); if (!empty) empty = (fgetc (fpout) == EOF); - fclose (fpout); + m_fclose(&fpout); fflush (pgperr); rewind (pgperr); @@ -1178,7 +1178,7 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) err = 1; fputs (buf, stdout); } - fclose (pgperr); + m_fclose(&pgperr); /* pause if there is any error output from PGP */ if (err) @@ -1255,7 +1255,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) pgpin = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(Tempdir), NULL); if (pgpin == NULL) { mutt_perror (pgpinfile); - fclose (fp); + m_fclose(&fp); return NULL; } @@ -1291,22 +1291,18 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) mutt_copy_stream (fp, pgpin); } m_fclose(&fp); - fclose (pgpin); + m_fclose(&pgpin); pgpout = m_tempfile(pgpoutfile, sizeof(pgpoutfile), NONULL(Tempdir), NULL); pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL); if (pgpout == NULL || pgperr == NULL) { mutt_perror (pgpout ? pgperrfile : pgpoutfile); - fclose (pgpin); + m_fclose(&pgpin); unlink (pgpinfile); - if (pgpout) { - fclose (pgpout); - unlink (pgpoutfile); - } - if (pgperr) { - fclose(pgperr); - unlink(pgperrfile); - } + m_fclose(&pgpout); + unlink (pgpoutfile); + m_fclose(&pgperr); + unlink(pgperrfile); return NULL; } @@ -1317,8 +1313,8 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) pgpinfile, keylist, flags)) == -1) { mutt_perror (_("Can't invoke PGP")); - fclose (pgpout); - fclose (pgperr); + m_fclose(&pgpout); + m_fclose(&pgperr); mutt_unlink (pgpinfile); unlink (pgpoutfile); return NULL; @@ -1328,7 +1324,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) *PgpPass = 0; if (flags & SIGN) fprintf (pgpin, "%s\n", PgpPass); - fclose (pgpin); + m_fclose(&pgpin); if (mutt_wait_filter (thepid) && option (OPTPGPCHECKEXIT)) empty = 1; @@ -1343,7 +1339,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) if (!empty) empty = (fgetc (pgpout) == EOF); - fclose (pgpout); + m_fclose(&pgpout); err = 0; @@ -1352,7 +1348,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) fputs (buff, stdout); } - fclose (pgperr); + m_fclose(&pgperr); if (err) mutt_any_key_to_continue (NULL); diff --git a/lib-crypt/pgpkey.c b/lib-crypt/pgpkey.c index 637e322..a3b3ca2 100644 --- a/lib-crypt/pgpkey.c +++ b/lib-crypt/pgpkey.c @@ -507,7 +507,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, address_t * p, const char *s) break; } if ((fp = safe_fopen (tempfile, "w")) == NULL) { - fclose (devnull); + m_fclose(&devnull); mutt_perror (_("Can't create temporary file")); break; @@ -525,13 +525,13 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, address_t * p, const char *s) mutt_perror (_("Can't create filter")); unlink (tempfile); - fclose (fp); - fclose (devnull); + m_fclose(&fp); + m_fclose(&devnull); } mutt_wait_filter (thepid); - fclose (fp); - fclose (devnull); + m_fclose(&fp); + m_fclose(&devnull); mutt_clear_error (); snprintf (cmd, sizeof (cmd), _("Key ID: 0x%s"), pgp_keyid (pgp_principal_key @@ -695,7 +695,7 @@ BODY *pgp_make_key_attachment (char *tempf) if ((devnull = fopen ("/dev/null", "w")) == NULL) { /* __FOPEN_CHECKED__ */ mutt_perror (_("Can't open /dev/null")); - fclose (tempfp); + m_fclose(&tempfp); if (tempf == tempfb) unlink (tempf); return NULL; @@ -710,15 +710,15 @@ BODY *pgp_make_key_attachment (char *tempf) mutt_perror (_("Can't create filter")); unlink (tempf); - fclose (tempfp); - fclose (devnull); + m_fclose(&tempfp); + m_fclose(&devnull); return NULL; } mutt_wait_filter (thepid); - fclose (tempfp); - fclose (devnull); + m_fclose(&tempfp); + m_fclose(&devnull); att = body_new(); att->filename = m_strdup(tempf); diff --git a/lib-crypt/smime.c b/lib-crypt/smime.c index 0080b6a..f5700a2 100644 --- a/lib-crypt/smime.c +++ b/lib-crypt/smime.c @@ -356,7 +356,7 @@ char *smime_ask_for_key (char *prompt, char *mailbox __attribute__((unused)), if (fgets (buf, sizeof (buf), idx)) cert_num++; } - fclose (idx); + m_fclose(&idx); for (;;) { *qry = 0; @@ -399,7 +399,7 @@ char *smime_ask_for_key (char *prompt, char *mailbox __attribute__((unused)), cur++; } - fclose (idx); + m_fclose(&idx); /* Make Helpstring */ helpstr[0] = 0; @@ -787,7 +787,7 @@ static int smime_handle_cert_email (char *certificate, char *mailbox, fpout = m_tempfile (tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL); if (!fpout) { - fclose (fperr); + m_fclose(&fperr); mutt_perror (tmpfname); return 1; } @@ -798,8 +798,8 @@ static int smime_handle_cert_email (char *certificate, char *mailbox, certificate, NULL, NULL, NULL, NULL, NULL, SmimeGetCertEmailCommand)) == -1) { mutt_message (_("Error: unable to create OpenSSL subprocess!")); - fclose (fperr); - fclose (fpout); + m_fclose(&fperr); + m_fclose(&fpout); return 1; } @@ -847,8 +847,8 @@ static int smime_handle_cert_email (char *certificate, char *mailbox, else if (copy) ret = 2; - fclose (fpout); - fclose (fperr); + m_fclose(&fpout); + m_fclose(&fperr); return ret; } @@ -873,7 +873,7 @@ static char *smime_extract_certificate (char *infile) fpout = m_tempfile (pk7out, sizeof(tmpfname), NONULL(Tempdir), NULL); if (!fpout) { - fclose (fperr); + m_fclose(&fperr); mutt_perror (pk7out); return NULL; } @@ -887,8 +887,8 @@ static char *smime_extract_certificate (char *infile) SmimePk7outCommand)) == -1) { mutt_any_key_to_continue (_ ("Error: unable to create OpenSSL subprocess!")); - fclose (fperr); - fclose (fpout); + m_fclose(&fperr); + m_fclose(&fpout); mutt_unlink (pk7out); return NULL; } @@ -903,19 +903,19 @@ static char *smime_extract_certificate (char *infile) empty = (fgetc (fpout) == EOF); - fclose (fpout); + m_fclose(&fpout); if (empty) { mutt_perror (pk7out); mutt_copy_stream (fperr, stdout); - fclose (fperr); + m_fclose(&fperr); mutt_unlink (pk7out); return NULL; } fpout = m_tempfile (certfile, sizeof(certfile), NONULL(Tempdir), NULL); if (!fpout) { - fclose (fperr); + m_fclose(&fperr); mutt_unlink (pk7out); mutt_perror (certfile); return NULL; @@ -929,8 +929,8 @@ static char *smime_extract_certificate (char *infile) SmimeGetCertCommand)) == -1) { mutt_any_key_to_continue (_ ("Error: unable to create OpenSSL subprocess!")); - fclose (fperr); - fclose (fpout); + m_fclose(&fperr); + m_fclose(&fpout); mutt_unlink (pk7out); mutt_unlink (certfile); return NULL; @@ -947,14 +947,14 @@ static char *smime_extract_certificate (char *infile) empty = (fgetc (fpout) == EOF); if (empty) { mutt_copy_stream (fperr, stdout); - fclose (fpout); - fclose (fperr); + m_fclose(&fpout); + m_fclose(&fperr); mutt_unlink (certfile); return NULL; } - fclose (fpout); - fclose (fperr); + m_fclose(&fpout); + m_fclose(&fperr); return m_strdup(certfile); } @@ -976,7 +976,7 @@ static char *smime_extract_signer_certificate (char *infile) m_tempfile (certfile, sizeof(certfile), NONULL(Tempdir), NULL); if (!fpout) { - fclose (fperr); + m_fclose(&fperr); mutt_perror (certfile); return NULL; } @@ -989,8 +989,8 @@ static char *smime_extract_signer_certificate (char *infile) SmimeGetSignerCertCommand)) == -1) { mutt_any_key_to_continue (_ ("Error: unable to create OpenSSL subprocess!")); - fclose (fperr); - fclose (fpout); + m_fclose(&fperr); + m_fclose(&fpout); mutt_unlink (pk7out); mutt_unlink (certfile); return NULL; @@ -1003,18 +1003,18 @@ static char *smime_extract_signer_certificate (char *infile) rewind (fperr); fflush (fperr); empty = (fgetc (fpout) == EOF); + m_fclose(&fpout); + if (empty) { mutt_endwin (NULL); mutt_copy_stream (fperr, stdout); mutt_any_key_to_continue (NULL); - fclose (fpout); - fclose (fperr); + m_fclose(&fperr); mutt_unlink (certfile); return NULL; } - fclose (fpout); - fclose (fperr); + m_fclose(&fperr); return m_strdup(certfile); } @@ -1036,7 +1036,7 @@ void smime_invoke_import (char *infile, char *mailbox __attribute__ ((unused))) fpout = m_tempfile (tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL); if (!fpout) { - fclose (fperr); + m_fclose(&fperr); mutt_perror (tmpfname); return; } @@ -1059,7 +1059,7 @@ void smime_invoke_import (char *infile, char *mailbox __attribute__ ((unused))) } fputs (buf, smimein); fputc ('\n', smimein); - fclose (smimein); + m_fclose(&smimein); mutt_wait_filter (thepid); @@ -1075,13 +1075,10 @@ void smime_invoke_import (char *infile, char *mailbox __attribute__ ((unused))) mutt_copy_stream (fpout, stdout); mutt_copy_stream (fperr, stdout); - fclose (fpout); - fclose (fperr); - + m_fclose(&fpout); + m_fclose(&fperr); } - - int smime_verify_sender (HEADER * h) { char *mbox = NULL, *certfile, tempfname[_POSIX_PATH_MAX]; @@ -1102,7 +1099,7 @@ int smime_verify_sender (HEADER * h) mutt_copy_message (fpout, Context, h, 0, 0); fflush (fpout); - fclose (fpout); + m_fclose(&fpout); if (h->env->from) { h->env->from = mutt_expand_aliases (h->env->from); @@ -1197,7 +1194,7 @@ BODY *smime_build_smime_entity (BODY * a, char *certlist) smimeerr = m_tempfile (smimeerrfile, sizeof(smimeerrfile), NONULL(Tempdir), NULL); if (!smimeerr) { mutt_perror (smimeerrfile); - fclose (fpout); + m_fclose(&fpout); mutt_unlink (tempfile); return NULL; } @@ -1207,8 +1204,8 @@ BODY *smime_build_smime_entity (BODY * a, char *certlist) if (!fptmp) { mutt_perror (smimeinfile); mutt_unlink (tempfile); - fclose (fpout); - fclose (smimeerr); + m_fclose(&fpout); + m_fclose(&smimeerr); return NULL; } @@ -1231,19 +1228,19 @@ BODY *smime_build_smime_entity (BODY * a, char *certlist) mutt_write_mime_header (a, fptmp); fputc ('\n', fptmp); mutt_write_mime_body (a, fptmp); - fclose (fptmp); + m_fclose(&fptmp); if ((thepid = smime_invoke_encrypt (&smimein, NULL, NULL, -1, fileno (fpout), fileno (smimeerr), smimeinfile, certfile)) == -1) { - fclose (smimeerr); + m_fclose(&smimeerr); mutt_unlink (smimeinfile); mutt_unlink (certfile); return (NULL); } - fclose (smimein); + m_fclose(&smimein); mutt_wait_filter (thepid); mutt_unlink (smimeinfile); @@ -1252,7 +1249,7 @@ BODY *smime_build_smime_entity (BODY * a, char *certlist) fflush (fpout); rewind (fpout); empty = (fgetc (fpout) == EOF); - fclose (fpout); + m_fclose(&fpout); fflush (smimeerr); rewind (smimeerr); @@ -1260,7 +1257,7 @@ BODY *smime_build_smime_entity (BODY * a, char *certlist) err = 1; fputs (buf, stdout); } - fclose (smimeerr); + m_fclose(&smimeerr); /* pause if there is any error output from SMIME */ if (err) @@ -1322,7 +1319,7 @@ BODY *smime_sign_message (BODY * a) smimeout = m_tempfile (signedfile, sizeof(signedfile), NONULL(Tempdir), NULL); if (!smimeout) { mutt_perror (signedfile); - fclose (sfp); + m_fclose(&sfp); mutt_unlink (filetosign); return NULL; } @@ -1330,7 +1327,7 @@ BODY *smime_sign_message (BODY * a) mutt_write_mime_header (a, sfp); fputc ('\n', sfp); mutt_write_mime_body (a, sfp); - fclose (sfp); + m_fclose(&sfp); @@ -1350,14 +1347,14 @@ BODY *smime_sign_message (BODY * a) filetosign)) == -1) { mutt_perror (_("Can't open OpenSSL subprocess!")); - fclose (smimeout); + m_fclose(&smimeout); mutt_unlink (signedfile); mutt_unlink (filetosign); return NULL; } fputs (SmimePass, smimein); fputc ('\n', smimein); - fclose (smimein); + m_fclose(&smimein); mutt_wait_filter (thepid); @@ -1370,13 +1367,13 @@ BODY *smime_sign_message (BODY * a) err = 1; fputs (buffer, stdout); } - fclose (smimeerr); + m_fclose(&smimeerr); fflush (smimeout); rewind (smimeout); empty = (fgetc (smimeout) == EOF); - fclose (smimeout); + m_fclose(&smimeout); mutt_unlink (filetosign); @@ -1490,7 +1487,7 @@ int smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) sigbdy->length = ftello (s->fpout); sigbdy->offset = 0; - fclose (s->fpout); + m_fclose(&s->fpout); /* restore final destination and substitute the tempfile for input */ s->fpout = fp; @@ -1514,8 +1511,7 @@ int smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) if ((thepid = smime_invoke_verify (NULL, &smimeout, NULL, -1, -1, fileno (smimeerr), tempfile, signedfile, 0)) != -1) { - fflush (smimeout); - fclose (smimeout); + m_fclose(&smimeout); if (mutt_wait_filter (thepid)) badsig = -1; @@ -1538,7 +1534,7 @@ int smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) fflush (smimeerr); rewind (smimeerr); mutt_copy_stream (smimeerr, s->fpout); - fclose (smimeerr); + m_fclose(&smimeerr); state_attach_puts (_("[-- End of OpenSSL output --]\n\n"), s); @@ -1549,7 +1545,7 @@ int smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) sigbdy->offset = tmpoffset; /* restore the original source stream */ - fclose (s->fpin); + m_fclose(&s->fpin); s->fpin = fp; @@ -1593,7 +1589,7 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) smimeerr = m_tempfile(errfile, sizeof(errfile), NONULL(Tempdir), NULL); if (!smimeerr) { mutt_perror (errfile); - fclose (smimeout); + m_fclose(&smimeout); return NULL; } mutt_unlink (errfile); @@ -1601,8 +1597,8 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) tmpfp = m_tempfile (tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL); if (!tmpfp) { mutt_perror (tmpfname); - fclose (smimeout); - fclose (smimeerr); + m_fclose(&smimeout); + m_fclose(&smimeerr); return NULL; } @@ -1610,16 +1606,13 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) last_pos = m->offset; mutt_copy_bytes (s->fpin, tmpfp, m->length); - - fflush (tmpfp); - fclose (tmpfp); + m_fclose(&tmpfp); if ((type & ENCRYPT) && (thepid = smime_invoke_decrypt (&smimein, NULL, NULL, -1, fileno (smimeout), fileno (smimeerr), tmpfname)) == -1) { - fclose (smimeout); - smimeout = NULL; + m_fclose(&smimeout); mutt_unlink (tmpfname); if (s->flags & M_DISPLAY) state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! --]\n"), s); @@ -1630,8 +1623,7 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) fileno (smimeout), fileno (smimeerr), NULL, tmpfname, SIGNOPAQUE)) == -1) { - fclose (smimeout); - smimeout = NULL; + m_fclose(&smimeout); mutt_unlink (tmpfname); if (s->flags & M_DISPLAY) state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! --]\n"), s); @@ -1646,7 +1638,7 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) fputc ('\n', smimein); } - fclose (smimein); + m_fclose(&smimein); mutt_wait_filter (thepid); mutt_unlink (tmpfname); @@ -1681,7 +1673,7 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) fpout = m_tempfile (tmptmpfname, sizeof(tmptmpfname), NONULL(Tempdir), NULL); if (!fpout) { mutt_perror (tmptmpfname); - fclose (smimeout); + m_fclose(&smimeout); return NULL; } } @@ -1711,12 +1703,11 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) } } - fclose (smimeout); - smimeout = NULL; + m_fclose(&smimeout); mutt_unlink (outfile); if (!outFile) { - fclose (fpout); + m_fclose(&fpout); mutt_unlink (tmptmpfname); } fpout = NULL; @@ -1745,7 +1736,7 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) m->goodsig = p->goodsig; m->badsig = p->badsig; } - fclose (smimeerr); + m_fclose(&smimeerr); return (p); } diff --git a/lib-lib/file.c b/lib-lib/file.c index 56bcf1f..584fcdb 100644 --- a/lib-lib/file.c +++ b/lib-lib/file.c @@ -200,7 +200,7 @@ void mutt_unlink(const char *s) fwrite(buf, 1, MIN(ssizeof(buf), sb.st_size), f); sb.st_size -= MIN(ssizeof(buf), sb.st_size); } - fclose (f); + m_fclose(&f); } } } @@ -258,13 +258,13 @@ int mutt_rename_file(char *oldfile, char *newfile) nfp = safe_fopen(newfile, "w"); if (!nfp) { - fclose (ofp); + m_fclose(&ofp); return 3; } mutt_copy_stream(ofp, nfp); - fclose(nfp); - fclose(ofp); + m_fclose(&nfp); + m_fclose(&ofp); mutt_unlink(oldfile); return 0; } diff --git a/lib-mime/rfc1524.c b/lib-mime/rfc1524.c index 08090e0..39e46e6 100644 --- a/lib-mime/rfc1524.c +++ b/lib-mime/rfc1524.c @@ -338,7 +338,7 @@ rfc1524_mailcap_parse(BODY *a, const char *filename, const char *type, rfc1524_entry_init(entry); } } /* while (!found && (buf = mutt_read_line ())) */ - fclose (fp); + m_fclose(&fp); error: p_delete(&buf); diff --git a/lib-mime/rfc3676.c b/lib-mime/rfc3676.c index 133fe3c..68bf1f5 100644 --- a/lib-mime/rfc3676.c +++ b/lib-mime/rfc3676.c @@ -227,7 +227,7 @@ void rfc3676_space_stuff (HEADER* hdr) { out = m_tempfile(tmpf, sizeof(tmpf), NONULL(Tempdir), NULL); if (!out) { - fclose(in); + m_fclose(&in); return; } @@ -237,8 +237,8 @@ void rfc3676_space_stuff (HEADER* hdr) { } fputs (buf, out); } - fclose (in); - fclose (out); + m_fclose(&in); + m_fclose(&out); mutt_set_mtime (hdr->content->filename, tmpf); unlink (hdr->content->filename); m_strreplace(&hdr->content->filename, tmpf); diff --git a/lib-mx/compress.c b/lib-mx/compress.c index 3770fef..e89d438 100644 --- a/lib-mx/compress.c +++ b/lib-mx/compress.c @@ -221,7 +221,7 @@ int mutt_open_read_compressed (CONTEXT * ctx) } mutt_block_signals (); if (mbox_lock_compressed (ctx, fp, 0, 1) == -1) { - fclose (fp); + m_fclose(&fp); mutt_unblock_signals (); mutt_error _("Unable to lock mailbox!"); @@ -236,7 +236,7 @@ int mutt_open_read_compressed (CONTEXT * ctx) rc = mutt_system (cmd); mbox_unlock_compressed (ctx, fp); mutt_unblock_signals (); - fclose (fp); + m_fclose(&fp); if (rc) { mutt_any_key_to_continue (NULL); @@ -290,7 +290,7 @@ int mutt_open_append_compressed (CONTEXT * ctx) if (!is_new (ctx->realpath)) if (ctx->magic == M_MBOX || ctx->magic == M_MMDF) if ((fh = safe_fopen (ctx->path, "w"))) - fclose (fh); + m_fclose(&fh); /* No error checking - the parent function will catch it */ return (0); @@ -300,9 +300,8 @@ int mutt_open_append_compressed (CONTEXT * ctx) void mutt_fast_close_compressed (CONTEXT * ctx) { if (ctx->cinfo) { - if (ctx->fp) - fclose (ctx->fp); - ctx->fp = NULL; + m_fclose(&ctx->fp); + /* if the folder was removed, remove the gzipped folder too */ if (access (ctx->path, F_OK) != 0 && !option (OPTSAVEEMPTY)) remove (ctx->realpath); @@ -335,7 +334,7 @@ int mutt_sync_compressed (CONTEXT * ctx) } mutt_block_signals (); if (mbox_lock_compressed (ctx, fp, 1, 1) == -1) { - fclose (fp); + m_fclose(&fp); mutt_unblock_signals (); mutt_error _("Unable to lock mailbox!"); @@ -359,7 +358,7 @@ int mutt_sync_compressed (CONTEXT * ctx) mbox_unlock_compressed (ctx, fp); mutt_unblock_signals (); - fclose (fp); + m_fclose(&fp); p_delete(&cmd); @@ -383,9 +382,7 @@ int mutt_slow_close_compressed (CONTEXT * ctx) return (0); } - if (ctx->fp) - fclose (ctx->fp); - ctx->fp = NULL; + m_fclose(&ctx->fp); if (!ctx->quiet) { if (append == ci->close) @@ -405,7 +402,7 @@ int mutt_slow_close_compressed (CONTEXT * ctx) } mutt_block_signals (); if (mbox_lock_compressed (ctx, fp, 1, 1) == -1) { - fclose (fp); + m_fclose(&fp); mutt_unblock_signals (); mutt_error _("Unable to lock mailbox!"); @@ -430,13 +427,13 @@ int mutt_slow_close_compressed (CONTEXT * ctx) p_delete(&cmd); mbox_unlock_compressed (ctx, fp); mutt_unblock_signals (); - fclose (fp); + m_fclose(&fp); return (-1); } mbox_unlock_compressed (ctx, fp); mutt_unblock_signals (); - fclose (fp); + m_fclose(&fp); remove_file (ctx); restore_path (ctx); p_delete(&cmd); diff --git a/lib-mx/mbox.c b/lib-mx/mbox.c index d1b2746..8e75038 100644 --- a/lib-mx/mbox.c +++ b/lib-mx/mbox.c @@ -657,14 +657,12 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused)) } } - if (fclose (fp) != 0) { - fp = NULL; + if (m_fclose(&fp) != 0) { unlink (tempfile); mutt_perror (tempfile); mutt_sleep (5); goto bail; } - fp = NULL; /* Save the state of this folder. */ if (stat (ctx->path, &statbuf) == -1) { @@ -709,11 +707,10 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused)) } } - fclose (fp); - fp = NULL; + m_fclose(&fp); mbox_unlock_mailbox (ctx); - if (fclose (ctx->fp) != 0 || i == -1) { + if (m_fclose(&ctx->fp) != 0 || i == -1) { /* error occured while writing the mailbox back, so keep the temp copy * around */ diff --git a/lib-mx/mh.c b/lib-mx/mh.c index c2abc74..2ff376f 100644 --- a/lib-mx/mh.c +++ b/lib-mx/mh.c @@ -548,7 +548,7 @@ static HEADER *maildir_parse_message (int magic, const char *fname, h->env = mutt_read_rfc822_header (f, h, 0, 0); fstat (fileno (f), &st); - fclose (f); + m_fclose(&f); if (!h->received) h->received = h->date_sent; diff --git a/lib-sys/mutt_ssl.c b/lib-sys/mutt_ssl.c index 9d658d4..4c7137a 100644 --- a/lib-sys/mutt_ssl.c +++ b/lib-sys/mutt_ssl.c @@ -510,7 +510,7 @@ static int check_certificate_by_digest (X509 * peercert) return 0; if (!X509_digest (peercert, EVP_sha1 (), peermd, &peermdlen)) { - fclose (fp); + m_fclose(&fp); return 0; } @@ -520,7 +520,7 @@ static int check_certificate_by_digest (X509 * peercert) break; } X509_free (cert); - fclose (fp); + m_fclose(&fp); return pass; } @@ -624,7 +624,7 @@ static int ssl_check_certificate (sslsockdata * data) if ((fp = fopen (SslCertFile, "a"))) { if (PEM_write_X509 (fp, data->cert)) done = 1; - fclose (fp); + m_fclose(&fp); } if (!done) { mutt_error (_("Warning: Couldn't save certificate")); diff --git a/lib-sys/mutt_ssl_gnutls.c b/lib-sys/mutt_ssl_gnutls.c index dfac2ca..1fff26d 100644 --- a/lib-sys/mutt_ssl_gnutls.c +++ b/lib-sys/mutt_ssl_gnutls.c @@ -310,7 +310,7 @@ static int tls_compare_certificates (const gnutls_datum * peercert) } b64_data.size = fread (b64_data.data, 1, b64_data.size, fd1); - fclose (fd1); + m_fclose(&fd1); do { ret = gnutls_pem_base64_decode_alloc (NULL, &b64_data, &cert); @@ -412,7 +412,7 @@ static int tls_check_stored_hostname (const gnutls_datum * cert, m_strcmp(linestr + pmatch[2].rm_so, buf) == 0) { regfree (&preg); p_delete(&linestr); - fclose (fp); + m_fclose(&fp); return 1; } } @@ -420,7 +420,7 @@ static int tls_check_stored_hostname (const gnutls_datum * cert, } regfree (&preg); - fclose (fp); + m_fclose(&fp); } /* not found a matching name */ @@ -761,7 +761,7 @@ static int tls_check_certificate (CONNECTION * conn) gnutls_free (pemdata.data); } } - fclose (fp); + m_fclose(&fp); } if (!done) { mutt_error (_("Warning: Couldn't save certificate")); diff --git a/lib-ui/query.c b/lib-ui/query.c index b76eb18..62ecd9a 100644 --- a/lib-ui/query.c +++ b/lib-ui/query.c @@ -119,7 +119,7 @@ static QUERY *run_query (char *s, int quiet) } } p_delete(&buf); - fclose (fp); + m_fclose(&fp); if (mutt_wait_filter (thepid)) { if (!quiet) mutt_error ("%s", msg); diff --git a/main.c b/main.c index 96493be..3624bb6 100644 --- a/main.c +++ b/main.c @@ -745,7 +745,7 @@ int main (int argc, char **argv) if (!option (OPTNOCURSES)) mutt_endwin (NULL); perror (tempfile); - fclose (fin); + m_fclose(&fin); p_delete(&tempfile); exit (1); } @@ -753,9 +753,9 @@ int main (int argc, char **argv) mutt_copy_stream (fin, fout); else if (bodytext) fputs (bodytext, fout); - fclose (fout); + m_fclose(&fout); if (fin && fin != stdin) - fclose (fin); + m_fclose(&fin); } } diff --git a/makedoc.c b/makedoc.c index 98fd035..e2cfc67 100644 --- a/makedoc.c +++ b/makedoc.c @@ -165,7 +165,7 @@ int main (int argc, char *argv[]) } if (f != stdin) - fclose (f); + m_fclose(&f); exit (1); } diff --git a/mutt_libesmtp.c b/mutt_libesmtp.c index 98533e7..0ee85c4 100644 --- a/mutt_libesmtp.c +++ b/mutt_libesmtp.c @@ -388,8 +388,7 @@ int mutt_libesmtp_invoke (address_t * from, /* the sender */ } Done: - if (fp != NULL) - fclose (fp); + m_fclose(&fp); if (hostportstr != NULL) p_delete(&hostportstr); if (session != NULL) diff --git a/muttlib.c b/muttlib.c index 185a878..97e650f 100644 --- a/muttlib.c +++ b/muttlib.c @@ -904,7 +904,7 @@ int mutt_extract_token(BUFFER *dest, BUFFER *tok, int flags) /* read line */ p_clear(&expn, 1); expn.data = mutt_read_line(NULL, &expn.dsize, fp, &line); - fclose(fp); + m_fclose(&fp); mutt_wait_filter(pid); /* if we got output, make a new string consiting of the shell ouptput diff --git a/nntp/newsrc.c b/nntp/newsrc.c index fef72fc..bb477f5 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -129,7 +129,7 @@ static int slurp_newsrc (NNTP_SERVER * news) return -1; /* hmm, should we use dotlock? */ if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) { - fclose (fp); + m_fclose(&fp); return -1; } @@ -139,7 +139,7 @@ static int slurp_newsrc (NNTP_SERVER * news) p_delete(&buf); mx_unlock_file (news->newsrc, fileno (fp), 0); - fclose (fp); + m_fclose(&fp); return 0; } @@ -235,7 +235,7 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news) mutt_newsgroup_stat (data); } } - fclose (idx); + m_fclose(&idx); return 0; } @@ -619,13 +619,13 @@ static int mutt_update_list_file (char *filename, char *section, /* if file not exist, create it */ if ((ifp = safe_fopen (filename, "a"))) - fclose (ifp); + m_fclose(&ifp); if (!(ifp = safe_fopen (filename, "r"))) { mutt_error (_("Unable to open %s for reading"), filename); return -1; } if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) { - fclose (ifp); + m_fclose(&ifp); mutt_error (_("Unable to lock %s"), filename); return -1; } @@ -638,7 +638,7 @@ static int mutt_update_list_file (char *filename, char *section, m_strcpy(tmpfile, sizeof(tmpfile), basename(filename)); mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile)); if (!(ofp = fopen (tmpfile, "w"))) { - fclose (ifp); + m_fclose(&ifp); mutt_error (_("Unable to open %s for writing"), tmpfile); return -1; } @@ -700,8 +700,8 @@ static int mutt_update_list_file (char *filename, char *section, r = fputc ('\n', ofp); } mx_unlock_file (filename, fileno (ifp), 0); - fclose (ofp); - fclose (ifp); + m_fclose(&ofp); + m_fclose(&ifp); if (r == EOF) { unlink (tmpfile); mutt_error (_("Can't write %s"), tmpfile); @@ -848,13 +848,13 @@ int nntp_save_cache_index (NNTP_SERVER * news) snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group, d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n'); if (fputs (buf, f) == EOF) { - fclose (f); + m_fclose(&f); unlink (file); return -1; } } } - fclose (f); + m_fclose(&f); if (nntp_update_cacheindex (news, NULL)) { unlink (file); @@ -921,7 +921,7 @@ int nntp_save_cache_group (CONTEXT * ctx) snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n", h->content->length, h->lines, NONULL (h->env->xref)); if (fputs (buf, f) == EOF) { - fclose (f); + m_fclose(&f); unlink (file); return -1; } @@ -933,7 +933,7 @@ int nntp_save_cache_group (CONTEXT * ctx) Sort = save; mutt_sort_headers (ctx, 0); } - fclose (f); + m_fclose(&f); if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv, (NNTP_DATA *) ctx->data)) { diff --git a/nntp/nntp.c b/nntp/nntp.c index a2388d9..35a1b1b 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -448,14 +448,14 @@ static int nntp_read_header (CONTEXT * ctx, const char *msgid, ret = mutt_nntp_fetch (nntp_data, buf, NULL, NULL, nntp_read_tempfile, f, 0); if (ret) { - fclose (f); + m_fclose(&f); unlink (tempfile); return (ret == -1 ? -1 : 1); } h->article_num = article_num; h->env = mutt_read_rfc822_header (f, h, 0, 0); - fclose (f); + m_fclose(&f); unlink (tempfile); if (h->env->xref != NULL) @@ -725,7 +725,7 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first, mutt_message ("%s %d/%d", msg2, c, r); add_xover_line (buf, &fc); } - fclose (f); + m_fclose(&f); nntp_data->lastLoaded = fc.last; first = fc.last + 1; if (ctx->msgcount > oldmsgcount) @@ -940,7 +940,7 @@ int nntp_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) } if (ret) { - fclose (msg->fp); + m_fclose(&msg->fp); unlink (path); p_delete(&cache->path); return -1; @@ -1022,7 +1022,7 @@ int nntp_post (const char *msg) else mutt_socket_write(nntp_data->nserv->conn, buf + 1); } - fclose (f); + m_fclose(&f); if (buf[m_strlen(buf) - 1] != '\n') mutt_socket_write(nntp_data->nserv->conn, "\r\n"); @@ -1344,7 +1344,7 @@ int nntp_get_cache_all (NNTP_SERVER * serv) i++; } add_group (NULL, NULL); - fclose (f); + m_fclose(&f); mutt_clear_error (); return 0; } diff --git a/pager.c b/pager.c index 0c9441f..9c2d797 100644 --- a/pager.c +++ b/pager.c @@ -1426,7 +1426,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra) if (stat (fname, &sb) != 0) { mutt_perror (fname); - fclose (fp); + m_fclose(&fp); return (-1); } unlink (fname); @@ -2559,7 +2559,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra) } } - fclose (fp); + m_fclose(&fp); if (IsHeader (extra)) { Context->msgnotreadyet = -1; if (rc == -1) diff --git a/pattern.c b/pattern.c index c8dff19..1eee48c 100644 --- a/pattern.c +++ b/pattern.c @@ -149,7 +149,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno) { mx_close_message (&msg); if (fp) { - fclose (fp); + m_fclose(&fp); unlink (tempfile); } return (0); @@ -200,7 +200,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno) mx_close_message (&msg); if (option (OPTTHOROUGHSRC)) { - fclose (fp); + m_fclose(&fp); unlink (tempfile); } } diff --git a/pgppubring.c b/pgppubring.c index b98b321..d7e5612 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -773,9 +773,7 @@ static void pgpring_find_candidates (char *ringfile, const char *hints[], FGETPOS (rfp, pos); } - - fclose (rfp); - + m_fclose(&rfp); } static void print_userid (const char *id) diff --git a/pop/pop.c b/pop/pop.c index 713743f..40df878 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -103,7 +103,7 @@ static pop_query_status pop_read_header (POP_DATA * pop_data, HEADER * h) } } - fclose (f); + m_fclose(&f); unlink (tempfile); return ret; } diff --git a/postpone.c b/postpone.c index fd06b62..d8d8cf5 100644 --- a/postpone.c +++ b/postpone.c @@ -656,7 +656,7 @@ bail: /* that's it. */ if (bfp != fp) - fclose (bfp); + m_fclose(&bfp); if (msg) mx_close_message (&msg); diff --git a/recvattach.c b/recvattach.c index c07ad2f..74a59fa 100644 --- a/recvattach.c +++ b/recvattach.c @@ -505,14 +505,14 @@ void mutt_save_attachment_list (FILE * fp, int tag, BODY * top, HEADER * hdr, rc = mutt_save_attachment (fp, top, tfile, append, hdr); if (rc == 0 && AttachSep && (fpout = fopen (tfile, "a")) != NULL) { fprintf (fpout, "%s", AttachSep); - fclose (fpout); + m_fclose(&fpout); } } else { rc = mutt_save_attachment (fp, top, tfile, M_SAVE_APPEND, hdr); if (rc == 0 && AttachSep && (fpout = fopen (tfile, "a")) != NULL) { fprintf (fpout, "%s", AttachSep); - fclose (fpout); + m_fclose(&fpout); } } } @@ -597,7 +597,7 @@ static void pipe_attachment (FILE * fp, BODY * b, STATE * state) return; } mutt_copy_stream (ifp, state->fpout); - fclose (ifp); + m_fclose(&ifp); if (AttachSep) state_puts (AttachSep, state); } @@ -643,7 +643,7 @@ void mutt_pipe_attachment_list (FILE * fp, int tag, BODY * top, int afilter) mutt_endwin (NULL); thepid = mutt_create_filter (buf, &state.fpout, NULL, NULL); pipe_attachment_list (buf, fp, tag, top, afilter, &state); - fclose (state.fpout); + m_fclose(&state.fpout); if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY)) mutt_any_key_to_continue (NULL); } @@ -701,7 +701,7 @@ static void print_attachment_list (FILE * fp, int tag, BODY * top, 0) { if ((ifp = fopen (newfile, "r")) != NULL) { mutt_copy_stream (ifp, state->fpout); - fclose (ifp); + m_fclose(&ifp); if (AttachSep) state_puts (AttachSep, state); } @@ -738,7 +738,7 @@ void mutt_print_attachment_list (FILE * fp, int tag, BODY * top) p_clear(&state, 1); thepid = mutt_create_filter (NONULL (PrintCmd), &state.fpout, NULL, NULL); print_attachment_list (fp, tag, top, &state); - fclose (state.fpout); + m_fclose(&state.fpout); if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY)) mutt_any_key_to_continue (NULL); } @@ -1228,7 +1228,7 @@ void mutt_view_attachments (HEADER * hdr) idxmax = 0; if (need_secured && secured) { - fclose (fp); + m_fclose(&fp); body_list_wipe(&cur); } diff --git a/recvcmd.c b/recvcmd.c index a8e4b6b..f614ec9 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -543,21 +543,15 @@ static void attach_forward_bodies (FILE * fp, HEADER * hdr, } mutt_forward_trailer (tmpfp); - - fclose (tmpfp); - tmpfp = NULL; + m_fclose(&tmpfp); /* now that we have the template, send it. */ ci_send_message (flags, tmphdr, tmpbody, NULL, parent); return; bail: - - if (tmpfp) { - fclose (tmpfp); - mutt_unlink (tmpbody); - } - + m_fclose(&tmpfp); + mutt_unlink(tmpbody); header_delete(&tmphdr); } @@ -651,7 +645,7 @@ static void attach_forward_msgs (FILE * fp, HEADER * hdr __attribute__ ((unused) } } } - fclose (tmpfp); + m_fclose(&tmpfp); } else if (rc == M_YES) { /* do MIME encapsulation - we don't need to do much here */ last = &tmphdr->content; @@ -921,12 +915,12 @@ void mutt_attach_reply (FILE * fp, HEADER * hdr, copy_problematic_attachments (fp, &tmphdr->content, idx, idxlen, 0) == NULL) { header_delete(&tmphdr); - fclose (tmpfp); + m_fclose(&tmpfp); return; } } - fclose (tmpfp); + m_fclose(&tmpfp); if (ci_send_message (flags, tmphdr, tmpbody, NULL, parent) == 0) mutt_set_flag (Context, hdr, M_REPLIED, 1); diff --git a/send.c b/send.c index f86d00c..037c660 100644 --- a/send.c +++ b/send.c @@ -48,7 +48,7 @@ static void append_signature (FILE * f) else if (SignOffString) fputs ("\n", f); mutt_copy_stream (tmpfp, f); - fclose (tmpfp); + m_fclose(&tmpfp); if (thepid != -1) mutt_wait_filter (thepid); } @@ -986,12 +986,12 @@ static int send_message (HEADER * msg) fputc ('\n', tempfp); /* tie off the header. */ if ((mutt_write_mime_body (msg->content, tempfp) == -1)) { - fclose (tempfp); + m_fclose(&tempfp); unlink (tempfile); return (-1); } - if (fclose (tempfp) != 0) { + if (m_fclose(&tempfp) != 0) { mutt_perror (tempfile); unlink (tempfile); return (-1); diff --git a/sendlib.c b/sendlib.c index f5bbd84..2bad9a6 100644 --- a/sendlib.c +++ b/sendlib.c @@ -395,7 +395,7 @@ int mutt_write_mime_body (BODY * a, FILE * f) #undef write_as_text_part fgetconv_close (&fc); - fclose (fpin); + m_fclose(&fpin); return (ferror (f) ? -1 : 0); } @@ -885,7 +885,7 @@ int mutt_lookup_mime_type (BODY * att, const char *path) p = NULL; } } - fclose (f); + m_fclose(&f); } } @@ -918,7 +918,7 @@ void mutt_message_to_7bit (BODY * a, FILE * fp) a->offset = 0; if (stat (a->filename, &sb) == -1) { mutt_perror ("stat"); - fclose (fpin); + m_fclose(&fpin); } a->length = sb.st_size; } @@ -946,9 +946,9 @@ cleanup: p_delete(&line); if (fpin && !fp) - fclose (fpin); + m_fclose(&fpin); if (fpout) - fclose (fpout); + m_fclose(&fpout); else return; @@ -995,7 +995,7 @@ static void transform_to_7bit (BODY * a, FILE * fpin) } s.fpin = fpin; mutt_decode_attachment (a, &s); - fclose (s.fpout); + m_fclose(&s.fpout); a->d_filename = a->filename; a->filename = m_strdup(buff); a->unlink = 1; @@ -1167,7 +1167,7 @@ BODY *mutt_make_message_attach (CONTEXT * ctx, HEADER * hdr, int attach_msg) mutt_update_encoding (body); body->parts = body->hdr->content; - fclose (fp); + m_fclose(&fp); return (body); } @@ -2085,7 +2085,7 @@ static int _mutt_bounce_message (FILE * fp, HEADER * h, address_t * to, mutt_copy_header (fp, h, f, ch_flags, NULL); fputc ('\n', f); mutt_copy_bytes (fp, f, h->content->length); - fclose (f); + m_fclose(&f); ret = mutt_invoke_mta(env_from, to, NULL, NULL, tempfile, h->content->encoding == ENC8BIT); @@ -2265,7 +2265,7 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid, fflush (tempfp); if (ferror (tempfp)) { - fclose (tempfp); + m_fclose(&tempfp); unlink (tempfile); mx_commit_message (msg, &f); /* XXX - really? */ mx_close_message (&msg); @@ -2283,7 +2283,7 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid, /* copy the body and clean up */ rewind (tempfp); r = mutt_copy_stream (tempfp, msg->fp); - if (fclose (tempfp) != 0) + if (m_fclose(&tempfp) != 0) r = -1; /* if there was an error, leave the temp version */ if (!r)