From: Paweł Pękala Date: Thu, 6 Jan 2011 11:19:10 +0000 (+0000) Subject: 2011-01-06 [pawel] 3.7.8cvs28 X-Git-Tag: REL_3_7_9~51 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=be87cfd8e4824f4ee769b3d84b6ed0ba0f8756ce 2011-01-06 [pawel] 3.7.8cvs28 * src/export.c * src/import.c * src/messageview.c * src/prefs_actions.c * src/procmime.c * src/gtk/gtkaspell.c * src/plugins/pgpinline/pgpinline.c * src/plugins/pgpmime/pgpmime.c * src/plugins/smime/smime.c Fix memory/file descriptors leaks --- diff --git a/ChangeLog b/ChangeLog index 1a192adb6..dd1d5f032 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2011-01-06 [pawel] 3.7.8cvs28 + + * src/export.c + * src/import.c + * src/messageview.c + * src/prefs_actions.c + * src/procmime.c + * src/gtk/gtkaspell.c + * src/plugins/pgpinline/pgpinline.c + * src/plugins/pgpmime/pgpmime.c + * src/plugins/smime/smime.c + Fix memory/file descriptors leaks + 2011-01-06 [paul] 3.7.8cvs27 * src/plugins/pgpcore/sgpgme.c diff --git a/PATCHSETS b/PATCHSETS index e66176052..f9faa0abc 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -4101,3 +4101,4 @@ ( cvs diff -u -r 1.8.2.14 -r 1.8.2.15 src/unmime.c; ) > 3.7.8cvs25.patchset ( cvs diff -u -r 1.8.2.15 -r 1.8.2.16 src/unmime.c; ) > 3.7.8cvs26.patchset ( cvs diff -u -r 1.1.2.66 -r 1.1.2.67 src/plugins/pgpcore/sgpgme.c; ) > 3.7.8cvs27.patchset +( cvs diff -u -r 1.8.2.29 -r 1.8.2.30 src/export.c; cvs diff -u -r 1.13.2.28 -r 1.13.2.29 src/import.c; cvs diff -u -r 1.94.2.210 -r 1.94.2.211 src/messageview.c; cvs diff -u -r 1.60.2.71 -r 1.60.2.72 src/prefs_actions.c; cvs diff -u -r 1.49.2.134 -r 1.49.2.135 src/procmime.c; cvs diff -u -r 1.9.2.70 -r 1.9.2.71 src/gtk/gtkaspell.c; cvs diff -u -r 1.1.2.45 -r 1.1.2.46 src/plugins/pgpinline/pgpinline.c; cvs diff -u -r 1.1.2.56 -r 1.1.2.57 src/plugins/pgpmime/pgpmime.c; cvs diff -u -r 1.1.2.8 -r 1.1.2.9 src/plugins/smime/smime.c; ) > 3.7.8cvs28.patchset diff --git a/configure.ac b/configure.ac index 7a3738755..9de593559 100644 --- a/configure.ac +++ b/configure.ac @@ -12,7 +12,7 @@ MINOR_VERSION=7 MICRO_VERSION=8 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=27 +EXTRA_VERSION=28 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/export.c b/src/export.c index 9063460b2..6d56dc480 100644 --- a/src/export.c +++ b/src/export.c @@ -219,6 +219,7 @@ static void export_ok_cb(GtkWidget *widget, gpointer data) if (!src) { alertpanel_error(_("Couldn't find the source folder.")); gtk_widget_grab_focus(src_entry); + g_free(mbox); return; } else { export_ok = export_to_mbox(src, mbox); diff --git a/src/gtk/gtkaspell.c b/src/gtk/gtkaspell.c index 53409999b..1a2b20814 100644 --- a/src/gtk/gtkaspell.c +++ b/src/gtk/gtkaspell.c @@ -390,6 +390,7 @@ GtkAspell *gtkaspell_new(const gchar *dictionary, if (!alt_gtkaspeller) { gtkaspell_checkers_error_message( g_strdup_printf(_("Couldn't initialize %s speller."), dictionary)); + g_free(gtkaspell); return NULL; } @@ -666,6 +667,7 @@ static GtkAspeller *gtkaspeller_real_new(Dictionary *dict) if (!broker) { gtkaspell_checkers_error_message( g_strdup(_("Couldn't initialize Enchant broker."))); + g_free(gtkaspeller); return NULL; } if ((speller = set_dictionary(broker, dict)) == NULL) { @@ -673,6 +675,7 @@ static GtkAspeller *gtkaspeller_real_new(Dictionary *dict) g_strdup_printf(_("Couldn't initialize %s dictionary:"), dict->fullname)); gtkaspell_checkers_error_message( g_strdup(enchant_broker_get_error(broker))); + g_free(gtkaspeller); return NULL; } gtkaspeller->speller = speller; diff --git a/src/import.c b/src/import.c index 1e124fac4..b3500ede1 100644 --- a/src/import.c +++ b/src/import.c @@ -227,6 +227,7 @@ static void import_ok_cb(GtkWidget *widget, gpointer data) if (!dest) { alertpanel_error(_("Can't find the destination folder.")); gtk_widget_grab_focus(dest_entry); + g_free(mbox); return; } else { import_ok = proc_mbox(dest, mbox, FALSE, NULL); diff --git a/src/messageview.c b/src/messageview.c index 5a9d7286e..e5daf50c9 100644 --- a/src/messageview.c +++ b/src/messageview.c @@ -859,7 +859,7 @@ static gint disposition_notification_send(MsgInfo *msginfo) addrp = addr; /* write queue headers */ - if (fprintf(fp, "AF:\n" + ok=fprintf(fp, "AF:\n" "NF:0\n" "PS:10\n" "SRH:1\n" @@ -875,14 +875,11 @@ static gint disposition_notification_send(MsgInfo *msginfo) "R:<%s>\n", account->address, account->smtp_server?account->smtp_server:"", - addrp) < 0) { - g_free(addrp); - fclose(fp); - claws_unlink(tmp); - return -1; - } + addrp); g_free(addrp); + if (ok < 0) + goto FILE_ERROR; /* check whether we need to save the message */ outbox = account_get_special_folder(account, F_OUTBOX); @@ -890,61 +887,40 @@ static gint disposition_notification_send(MsgInfo *msginfo) outbox = NULL; if (outbox) { path = folder_item_get_identifier(outbox); - if (fprintf(fp, "SCF:%s\n", path) < 0) { - g_free(path); - fclose(fp); - claws_unlink(tmp); - return -1; - } + ok = fprintf(fp, "SCF:%s\n", path); g_free(path); + + if (ok < 0) + goto FILE_ERROR; } - if (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0) { - fclose(fp); - claws_unlink(tmp); - return -1; - } + if (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0) + goto FILE_ERROR; /* Date */ get_rfc822_date(buf, sizeof(buf)); - if (fprintf(fp, "Date: %s\n", buf) < 0) { - fclose(fp); - claws_unlink(tmp); - return -1; - } + if (fprintf(fp, "Date: %s\n", buf) < 0) + goto FILE_ERROR; /* From */ if (account->name && *account->name) { notification_convert_header (buf, sizeof(buf), account->name, strlen("From: ")); - if (fprintf(fp, "From: %s <%s>\n", buf, account->address) < 0) { - fclose(fp); - claws_unlink(tmp); - return -1; - } + if (fprintf(fp, "From: %s <%s>\n", buf, account->address) < 0) + goto FILE_ERROR; } else - if (fprintf(fp, "From: %s\n", account->address) < 0) { - fclose(fp); - claws_unlink(tmp); - return -1; - } - + if (fprintf(fp, "From: %s\n", account->address) < 0) + goto FILE_ERROR; - if (fprintf(fp, "To: %s\n", to) < 0) { - fclose(fp); - claws_unlink(tmp); - return -1; - } + if (fprintf(fp, "To: %s\n", to) < 0) + goto FILE_ERROR; /* Subject */ notification_convert_header(buf, sizeof(buf), msginfo->subject, strlen("Subject: ")); - if (fprintf(fp, "Subject: Disposition notification: %s\n", buf) < 0) { - fclose(fp); - claws_unlink(tmp); - return -1; - } + if (fprintf(fp, "Subject: Disposition notification: %s\n", buf) < 0) + goto FILE_ERROR; /* Message ID */ if (account->set_domain && account->domain) { @@ -965,11 +941,8 @@ static gint disposition_notification_send(MsgInfo *msginfo) } generate_msgid(buf, sizeof(buf), addr); - if (fprintf(fp, "Message-ID: <%s>\n", buf) < 0) { - fclose(fp); - claws_unlink(tmp); - return -1; - } + if (fprintf(fp, "Message-ID: <%s>\n", buf) < 0) + goto FILE_ERROR; } boundary = generate_mime_boundary("DN"); @@ -984,7 +957,7 @@ static gint disposition_notification_send(MsgInfo *msginfo) qp_encode_line(enc_sub, (const guchar *)msginfo->subject); g_strstrip(enc_sub); } - if (fprintf(fp, "MIME-Version: 1.0\n" + ok = fprintf(fp,"MIME-Version: 1.0\n" "Content-Type: multipart/report; report-type=disposition-notification;\n" " boundary=\"%s\"\n" "\n" @@ -1033,18 +1006,16 @@ static gint disposition_notification_send(MsgInfo *msginfo) orig_to?orig_to:"No To:", account->address, msginfo->msgid?msginfo->msgid:"NO MESSAGE ID", - boundary) < 0) { - fclose(fp); - claws_unlink(tmp); - g_free(boundary); - return -1; - } + boundary); g_free(enc_sub); g_free(orig_to); g_free(date); g_free(boundary); + if (ok < 0) + goto FILE_ERROR; + if (fclose(fp) == EOF) { FILE_OP_ERROR(tmp, "fclose"); claws_unlink(tmp); @@ -1081,6 +1052,11 @@ static gint disposition_notification_send(MsgInfo *msginfo) folder_item_remove_msg(queue, num); return ok; + +FILE_ERROR: + fclose(fp); + claws_unlink(tmp); + return -1; } static gboolean find_encrypted_func(GNode *node, gpointer data) diff --git a/src/plugins/pgpinline/pgpinline.c b/src/plugins/pgpinline/pgpinline.c index c89d2fe91..be95b0866 100644 --- a/src/plugins/pgpinline/pgpinline.c +++ b/src/plugins/pgpinline/pgpinline.c @@ -280,6 +280,7 @@ static gint pgpinline_check_signature(MimeInfo *mimeinfo) if ((err = gpgme_new(&data->ctx)) != GPG_ERR_NO_ERROR) { debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err)); privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err)); + g_free(textdata); return 0; } gpgme_set_textmode(data->ctx, 1); @@ -450,10 +451,7 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo) src_codeset) < 0) { FILE_OP_ERROR(fname, "fprintf"); privacy_set_error(_("Couldn't write to decrypted file %s"), fname); - g_free(fname); - gpgme_data_release(plain); - gpgme_release(ctx); - return NULL; + goto FILE_ERROR; } /* Store any part before encrypted text */ @@ -462,10 +460,7 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo) if (fwrite(textdata, 1, pos - textdata, dstfp) < pos - textdata) { FILE_OP_ERROR(fname, "fwrite"); privacy_set_error(_("Couldn't write to decrypted file %s"), fname); - g_free(fname); - gpgme_data_release(plain); - gpgme_release(ctx); - return NULL; + goto FILE_ERROR; } } @@ -474,20 +469,14 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo) dstfp) < strlen(_("\n--- Start of PGP/Inline encrypted data ---\n"))) { FILE_OP_ERROR(fname, "fwrite"); privacy_set_error(_("Couldn't write to decrypted file %s"), fname); - g_free(fname); - gpgme_data_release(plain); - gpgme_release(ctx); - return NULL; + goto FILE_ERROR; } chars = sgpgme_data_release_and_get_mem(plain, &len); if (len > 0) { if (fwrite(chars, 1, len, dstfp) < len) { FILE_OP_ERROR(fname, "fwrite"); privacy_set_error(_("Couldn't write to decrypted file %s"), fname); - g_free(fname); - gpgme_data_release(plain); - gpgme_release(ctx); - return NULL; + goto FILE_ERROR; } } /* Store any part after encrypted text */ @@ -496,10 +485,7 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo) dstfp) < strlen(_("--- End of PGP/Inline encrypted data ---\n"))) { FILE_OP_ERROR(fname, "fwrite"); privacy_set_error(_("Couldn't write to decrypted file %s"), fname); - g_free(fname); - gpgme_data_release(plain); - gpgme_release(ctx); - return NULL; + goto FILE_ERROR; } if (pos != NULL) { pos = strstr(pos, end_indicator); @@ -508,10 +494,7 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo) if (fwrite(pos, 1, strlen(pos), dstfp) < strlen(pos)) { FILE_OP_ERROR(fname, "fwrite"); privacy_set_error(_("Couldn't write to decrypted file %s"), fname); - g_free(fname); - gpgme_data_release(plain); - gpgme_release(ctx); - return NULL; + goto FILE_ERROR; } } } @@ -564,6 +547,13 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo) gpgme_release(ctx); return decinfo; + +FILE_ERROR: + fclose(dstfp); + g_free(fname); + gpgme_data_release(plain); + gpgme_release(ctx); + return NULL; } static gboolean pgpinline_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *from_addr) @@ -752,6 +742,7 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) { debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err)); privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err)); + g_free(kset); return FALSE; } i = 0; @@ -761,6 +752,7 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) if (err) { debug_print("can't add key '%s'[%d] (%s)\n", fprs[i],i, gpgme_strerror(err)); privacy_set_error(_("Couldn't add GPG key %s, %s"), fprs[i], gpgme_strerror(err)); + g_free(kset); return FALSE; } debug_print("found %s at %d\n", fprs[i], i); @@ -777,6 +769,7 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) if (!msgcontent->node->children) { debug_print("msgcontent->node->children NULL, bailing\n"); privacy_set_error(_("Malformed message")); + g_free(kset); return FALSE; } msgcontent = (MimeInfo *) msgcontent->node->children->data; @@ -788,6 +781,7 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) if (fp == NULL) { privacy_set_error(_("Couldn't create temporary file, %s"), strerror(errno)); perror("my_tmpfile"); + g_free(kset); return FALSE; } procmime_write_mimeinfo(msgcontent, fp); @@ -804,6 +798,7 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) { debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err)); privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err)); + g_free(kset); return FALSE; } gpgme_set_armor(ctx, 1); @@ -811,6 +806,7 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) err = gpgme_op_encrypt(ctx, kset, GPGME_ENCRYPT_ALWAYS_TRUST, gpgtext, gpgenc); enccontent = sgpgme_data_release_and_get_mem(gpgenc, &len); + g_free(kset); if (enccontent == NULL || len <= 0) { g_warning("sgpgme_data_release_and_get_mem failed"); diff --git a/src/plugins/pgpmime/pgpmime.c b/src/plugins/pgpmime/pgpmime.c index 84ba17d10..2c67ae004 100644 --- a/src/plugins/pgpmime/pgpmime.c +++ b/src/plugins/pgpmime/pgpmime.c @@ -425,7 +425,7 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo) gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *from_addr) { MimeInfo *msgcontent, *sigmultipart, *newinfo; - gchar *textstr, *micalg; + gchar *textstr, *micalg = NULL; FILE *fp; gchar *boundary = NULL; gchar *sigcontent; @@ -566,6 +566,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *fr if (sigcontent == NULL || len <= 0) { g_warning("sgpgme_data_release_and_get_mem failed"); privacy_set_error(_("Data signing failed, no contents.")); + g_free(micalg); return FALSE; } @@ -637,6 +638,7 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) if ((err = gpgme_new(&ctx)) != GPG_ERR_NO_ERROR) { debug_print(("Couldn't initialize GPG context, %s"), gpgme_strerror(err)); privacy_set_error(_("Couldn't initialize GPG context, %s"), gpgme_strerror(err)); + g_free(kset); return FALSE; } i = 0; @@ -646,6 +648,7 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) if (err) { debug_print("can't add key '%s'[%d] (%s)\n", fprs[i],i, gpgme_strerror(err)); privacy_set_error(_("Couldn't add GPG key %s, %s"), fprs[i], gpgme_strerror(err)); + g_free(kset); return FALSE; } debug_print("found %s at %d\n", fprs[i], i); @@ -674,6 +677,7 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) fp = my_tmpfile(); if (fp == NULL) { privacy_set_error(_("Couldn't create temporary file, %s"), strerror(errno)); + g_free(kset); return FALSE; } procmime_write_mimeinfo(encmultipart, fp); @@ -695,6 +699,7 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) enccontent = sgpgme_data_release_and_get_mem(gpgenc, &len); gpgme_data_release(gpgtext); g_free(textstr); + g_free(kset); if (enccontent == NULL || len <= 0) { g_warning("sgpgme_data_release_and_get_mem failed"); diff --git a/src/plugins/smime/smime.c b/src/plugins/smime/smime.c index 50d051db7..4a29f1dd2 100644 --- a/src/plugins/smime/smime.c +++ b/src/plugins/smime/smime.c @@ -459,6 +459,7 @@ static MimeInfo *smime_decrypt(MimeInfo *mimeinfo) if (len > 0) { if (fwrite(chars, 1, len, dstfp) < len) { FILE_OP_ERROR(fname, "fwrite"); + fclose(dstfp); g_free(fname); g_free(chars); gpgme_data_release(plain); @@ -524,7 +525,7 @@ static MimeInfo *smime_decrypt(MimeInfo *mimeinfo) gboolean smime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *from_addr) { MimeInfo *msgcontent, *sigmultipart, *newinfo; - gchar *textstr, *micalg; + gchar *textstr, *micalg = NULL; FILE *fp; gchar *boundary = NULL; gchar *sigcontent; @@ -647,12 +648,14 @@ gboolean smime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *from if (!sigcontent) { gpgme_release(ctx); + g_free(micalg); return FALSE; } real_content = sigcontent+strlen("-----BEGIN SIGNED MESSAGE-----\n"); if (!strstr(real_content, "-----END SIGNED MESSAGE-----")) { debug_print("missing end\n"); gpgme_release(ctx); + g_free(micalg); return FALSE; } *strstr(real_content, "-----END SIGNED MESSAGE-----") = '\0'; @@ -806,6 +809,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) fp = g_fopen(tmpfile, "wb"); if (fp == NULL) { perror("get_tmp_file"); + g_free(kset); return FALSE; } procmime_decode_content(msgcontent); @@ -816,6 +820,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) fp = g_fopen(tmpfile, "rb"); if (fp == NULL) { perror("get_tmp_file"); + g_free(kset); return FALSE; } g_free(tmpfile); @@ -833,6 +838,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) gpgme_op_encrypt(ctx, kset, GPGME_ENCRYPT_ALWAYS_TRUST, gpgtext, gpgenc); gpgme_release(ctx); + g_free(kset); enccontent = sgpgme_data_release_and_get_mem(gpgenc, &len); if (!enccontent) { diff --git a/src/prefs_actions.c b/src/prefs_actions.c index 61f843c48..55638adbc 100644 --- a/src/prefs_actions.c +++ b/src/prefs_actions.c @@ -506,6 +506,7 @@ void prefs_actions_write_config(void) fputc('\n', pfile->fp) == EOF) { FILE_OP_ERROR(rcpath, "fputs || fputc"); prefs_file_close_revert(pfile); + g_free(act); g_free(rcpath); return; } diff --git a/src/procmime.c b/src/procmime.c index b325797ea..eaec403b8 100644 --- a/src/procmime.c +++ b/src/procmime.c @@ -654,6 +654,7 @@ gint procmime_get_part(const gchar *outfile, MimeInfo *mimeinfo) while ((restlength > 0) && ((readlength = fread(buf, 1, restlength > BUFFSIZE ? BUFFSIZE : restlength, infp)) > 0)) { if (fwrite(buf, 1, readlength, outfp) != readlength) { saved_errno = errno; + fclose(infp); fclose(outfp); return -(saved_errno); }