Fix several memory leaks in RSSyl.
[claws.git] / src / plugins / rssyl / rssyl.c
index b76aeb7e48d1f6245cb78d0b52cdf2582f4302b2..d8f3892bce2d6884e7d4d0405e6697102f38d0a1 100644 (file)
@@ -203,8 +203,9 @@ static gchar *rssyl_get_new_msg_filename(FolderItem *dest)
 static void rssyl_get_last_num(Folder *folder, FolderItem *item)
 {
        gchar *path;
-       DIR *dp;
-       struct dirent *d;
+       const char *f;
+       GDir *dp;
+       GError *error = NULL;
        gint max = 0;
        gint num;
 
@@ -214,21 +215,25 @@ static void rssyl_get_last_num(Folder *folder, FolderItem *item)
        path = folder_item_get_path(item);
        g_return_if_fail(path != NULL);
 
-       if( (dp = opendir(path)) == NULL ) {
-               FILE_OP_ERROR(item->path, "opendir");
+       if( (dp = g_dir_open(path, 0, &error)) == NULL ) {
+               FILE_OP_ERROR(item->path, "g_dir_open");
+               debug_print("g_dir_open() failed on \"%s\", error %d (%s).\n",
+                               path, error->code, error->message);
+               g_error_free(error);
                g_free(path);
                return;
        }
 
        g_free(path);
 
-       while( (d = readdir(dp)) != NULL ) {
-               if( (num = to_number(d->d_name)) > 0 && dirent_is_regular_file(d) ) {
+       while( (f = g_dir_read_name(dp)) != NULL) {
+               if ((num = to_number(f)) > 0 &&
+                               g_file_test(f, G_FILE_TEST_IS_REGULAR)) {
                        if( max < num )
                                max = num;
                }
        }
-       closedir(dp);
+       g_dir_close(dp);
 
        debug_print("Last number in dir %s = %d\n", item->path, max);
        item->last_num = max;
@@ -650,8 +655,9 @@ static gint rssyl_get_num_list(Folder *folder, FolderItem *item,
                MsgNumberList **list, gboolean *old_uids_valid)
 {
        gchar *path;
-       DIR *dp;
-       struct dirent *d;
+       GDir *dp;
+       const gchar *d;
+       GError *error = NULL;
        gint num, nummsgs = 0;
 
        g_return_val_if_fail(item != NULL, -1);
@@ -663,22 +669,23 @@ static gint rssyl_get_num_list(Folder *folder, FolderItem *item,
        path = folder_item_get_path(item);
        g_return_val_if_fail(path != NULL, -1);
 
-       if( (dp = opendir(path)) == NULL ) {
-               FILE_OP_ERROR(item->path, "opendir");
+       if( (dp = g_dir_open(path, 0, &error)) == NULL ) {
+               debug_print("g_dir_open() failed on \"%s\", error %d (%s).\n",
+                               path, error->code, error->message);
+               g_error_free(error);
                g_free(path);
                return -1;
        }
 
        g_free(path);
 
-       while( (d = readdir(dp)) != NULL ) {
-               if( (num = to_number(d->d_name)) > 0 ) {
+       while( (d = g_dir_read_name(dp)) != NULL ) {
+               if( (num = to_number(d)) > 0 ) {
                        *list = g_slist_prepend(*list, GINT_TO_POINTER(num));
                        nummsgs++;
                }
        }
-
-       closedir(dp);
+       g_dir_close(dp);
 
        debug_print("RSSyl: get_num_list: returning %d\n", nummsgs);
 
@@ -690,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 || (