Fix several memory leaks in RSSyl.
authorAndrej Kacian <ticho@claws-mail.org>
Mon, 21 Sep 2015 20:46:41 +0000 (22:46 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Mon, 21 Sep 2015 20:46:41 +0000 (22:46 +0200)
Patch by Darko Koruga.

src/plugins/rssyl/rssyl.c
src/plugins/rssyl/rssyl_add_item.c
src/plugins/rssyl/rssyl_deleted.c

index eb95612..d8f3892 100644 (file)
@@ -697,13 +697,15 @@ static gboolean rssyl_is_msg_changed(Folder *folder, FolderItem *item,
 {
        GStatBuf s;
        gchar *path = NULL;
+       gchar *itempath = NULL;
 
        g_return_val_if_fail(folder != NULL, FALSE);
        g_return_val_if_fail(item != NULL, FALSE);
        g_return_val_if_fail(msginfo != NULL, FALSE);
 
-       path = g_strconcat(folder_item_get_path(item), G_DIR_SEPARATOR_S,
-                       itos(msginfo->msgnum), NULL);
+       itempath = folder_item_get_path(item);
+       path = g_strconcat(itempath, G_DIR_SEPARATOR_S, itos(msginfo->msgnum), NULL);
+       g_free(itempath);
 
        if (g_stat(path, &s) < 0 ||
                msginfo->size != s.st_size || (
index c2258f9..9b02498 100644 (file)
@@ -279,6 +279,7 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
        gchar *dirname = NULL;
        gchar *text = NULL;
        gchar *heading = NULL;
+       gchar *pathbasename = NULL;
        gchar hdr[1024];
        FeedItemEnclosure *enc = NULL;
        RFeedCtx *ctx;
@@ -311,14 +312,18 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
        /* Fix up subject, url and ID (rssyl_format_string()) so that
         * comparing doesn't break. */
        debug_print("RSSyl: fixing up subject '%s'\n", feed_item_get_title(feed_item));
-       feed_item_set_title(feed_item, rssyl_format_string(feed_item_get_title(feed_item), TRUE, TRUE));
+       tmp = rssyl_format_string(feed_item_get_title(feed_item), TRUE, TRUE);
+       feed_item_set_title(feed_item, tmp);
+       g_free(tmp);
        debug_print("RSSyl: fixing up URL\n");
-       feed_item_set_url(feed_item, rssyl_format_string(feed_item_get_url(feed_item),
-                               FALSE, TRUE));
+       tmp = rssyl_format_string(feed_item_get_url(feed_item), FALSE, TRUE);
+       feed_item_set_url(feed_item, tmp);
+       g_free(tmp);
        if( feed_item_get_id(feed_item) != NULL ) {
                debug_print("RSSyl: fixing up ID\n");
-               feed_item_set_id(feed_item, rssyl_format_string(feed_item_get_id(feed_item),
-                                       FALSE, TRUE));
+               tmp = rssyl_format_string(feed_item_get_id(feed_item), FALSE, TRUE);
+               feed_item_set_id(feed_item, tmp);
+               g_free(tmp);
        }
 
        /* If there's a summary, but no text, use summary as text. */
@@ -345,8 +350,10 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
 
                /* Store permflags of the old item. */
                ctx = (RFeedCtx *)old_item->data;
+               pathbasename = g_path_get_basename(ctx->path);
                msginfo = folder_item_get_msginfo((FolderItem *)ritem,
-                               atoi(g_path_get_basename(ctx->path)));
+                                               atoi(pathbasename));
+               g_free(pathbasename);
                oldperm_flags = msginfo->flags.perm_flags;
 
                ritem->items = g_slist_remove(ritem->items, old_item);
@@ -376,6 +383,7 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
                        RSSYL_TMP_TEMPLATE, NULL);
        if ((fd = g_mkstemp(template)) < 0) {
                g_warning("Couldn't g_mkstemp('%s'), not adding message!\n", template);
+               g_free(dirname);
                g_free(template);
                return;
        }
@@ -383,6 +391,7 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
        f = fdopen(fd, "w");
        if (f == NULL) {
                g_warning("Couldn't open file '%s', not adding message!\n", template);
+               g_free(dirname);
                g_free(template);
                return;
        }
@@ -528,6 +537,7 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
 
        d = folder_item_add_msg(&ritem->item, template, flags, TRUE);
        g_free(template);
+       g_free(flags);
 
        ctx = g_new0(RFeedCtx, 1);
        ctx->path = (gpointer)g_strdup_printf("%s%c%d", dirname,
@@ -535,6 +545,8 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
        ctx->last_seen = ritem->last_update;
        ((FeedItem *)ritem->items->data)->data = (gpointer)ctx;
 
+       g_free(dirname);
+
        /* Unset unread+new if the changed item wasn't set unread and user
         * doesn't want to see it unread because of the change. */
        if (dif != EXISTS_NEW) {
index 6f3a06e..ee2466b 100644 (file)
@@ -99,6 +99,7 @@ GSList *rssyl_deleted_update(RFolderItem *ritem)
 
        if (!g_file_test(deleted_file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
                debug_print("RSSyl: '%s' doesn't exist, ignoring\n", deleted_file);
+               g_free(deleted_file);
                return NULL;
        }
 
@@ -203,6 +204,7 @@ void rssyl_deleted_store(RFolderItem *ritem)
 
        path = _deleted_file_path(ritem);
        rssyl_deleted_store_internal(ritem->deleted_items, path);
+       g_free(path);
 }