Fix a leak, CID #1220437.
[claws.git] / src / plugins / smime / smime.c
index 5f7068b5133311c5f90e54c04b41c3cc3651a121..823ba373216bd0d95281f8f6a830ce85311a2020 100644 (file)
@@ -1,7 +1,6 @@
 /* 
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Colin Leroy <colin@colino.net> and 
- * the Claws Mail team
+ * Copyright (C) 1999-2016 Colin Leroy and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -14,8 +13,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -68,7 +66,7 @@ static PrivacyDataPGP *smime_new_privacydata()
        gpgme_ctx_t     ctx;
 
        if (gpgme_new(&ctx) != GPG_ERR_NO_ERROR) {
-               debug_print("gpgme_new failed");
+               debug_print("gpgme_new failed\n");
                return NULL;
        }
 
@@ -292,11 +290,13 @@ static gint smime_check_signature(MimeInfo *mimeinfo)
                                decinfo = g_node_first_child(newinfo->node) != NULL ?
                                        g_node_first_child(newinfo->node)->data : NULL;
 
-                               if (decinfo == NULL)
+                               if (decinfo == NULL) {
+                                       g_free(textstr);
                                        return -1;
+                               }
 
                                g_node_unlink(decinfo->node);
-                               procmime_mimeinfo_free_all(newinfo);
+                               procmime_mimeinfo_free_all(&newinfo);
                                decinfo->tmp = TRUE;
                                parentinfo = procmime_mimeinfo_parent(mimeinfo);
 
@@ -506,7 +506,7 @@ static MimeInfo *smime_decrypt(MimeInfo *mimeinfo)
        }
 
        g_node_unlink(decinfo->node);
-       procmime_mimeinfo_free_all(parseinfo);
+       procmime_mimeinfo_free_all(&parseinfo);
 
        decinfo->tmp = TRUE;
 
@@ -795,7 +795,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        tmpfile = get_tmp_file();
        fp = g_fopen(tmpfile, "wb");
        if (fp == NULL) {
-               perror("get_tmp_file");
+               FILE_OP_ERROR(tmpfile, "create");
                g_free(kset);
                return FALSE;
        }
@@ -806,7 +806,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        canonicalize_file_replace(tmpfile);
        fp = g_fopen(tmpfile, "rb");
        if (fp == NULL) {
-               perror("get_tmp_file");
+               FILE_OP_ERROR(tmpfile, "open");
                g_free(kset);
                return FALSE;
        }
@@ -829,7 +829,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        enccontent = sgpgme_data_release_and_get_mem(gpgenc, &len);
 
        if (!enccontent) {
-               g_warning("no enccontent\n");
+               g_warning("no enccontent");
                return FALSE;
        }
 
@@ -841,16 +841,18 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
                        fclose(fp);
                        claws_unlink(tmpfile);
                        g_free(tmpfile);
+                       g_free(enccontent);
                        return FALSE;
                }
                if (fclose(fp) == EOF) {
                        FILE_OP_ERROR(tmpfile, "fclose");
                        claws_unlink(tmpfile);
                        g_free(tmpfile);
+                       g_free(enccontent);
                        return FALSE;
                }
        } else {
-               perror("get_tmp_file");
+               FILE_OP_ERROR(tmpfile, "create");
                g_free(tmpfile);
                g_free(enccontent);
                return FALSE;
@@ -859,7 +861,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        g_free(textstr);
 
        /* create encrypted multipart */
-       procmime_mimeinfo_free_all(msgcontent);
+       procmime_mimeinfo_free_all(&msgcontent);
        g_node_append(mimeinfo->node, encmultipart->node);
 
        encmultipart->content = MIMECONTENT_FILE;