Various fixes
authorArkadiy Illarionov <qarkai@gmail.com>
Thu, 20 Jul 2023 21:58:24 +0000 (00:58 +0300)
committerColin Clark <colin.clark@cclark.uk>
Sat, 22 Jul 2023 15:43:14 +0000 (16:43 +0100)
src/bar-exif.cc
src/bar-gps.cc
src/bar-keywords.cc
src/dupe.cc
src/filedata.cc
src/view-file/view-file-list.cc

index bcf6378..a8a213d 100644 (file)
@@ -750,10 +750,11 @@ GList * bar_pane_exif_list()
                ped = static_cast<PaneExifData *>(g_object_get_data(G_OBJECT(pane), "pane_data"));
 
                list = gtk_container_get_children(GTK_CONTAINER(ped->vbox));
-               while (list)
+               GList *work = list;
+               while (work)
                        {
-                       entry = static_cast<GtkWidget *>(list->data);
-                       list = list->next;
+                       entry = static_cast<GtkWidget *>(work->data);
+                       work = work->next;
                        ee = static_cast<ExifEntry *>(g_object_get_data(G_OBJECT(entry), "entry_data"));
                        exif_list = g_list_append(exif_list, g_strdup(ee->title));
                        exif_list = g_list_append(exif_list, g_strdup(ee->key));
index 0f377ee..1f90892 100644 (file)
@@ -122,7 +122,6 @@ static void bar_pane_gps_close_save_cb(GenericDialog *UNUSED(gd), gpointer data)
                        metadata_write_GPS_coord(fd, "Xmp.exif.GPSLongitude", pgd->dest_longitude);
                        }
                }
-       g_list_free(work);
        g_list_free(pgd->geocode_list);
 }
 
@@ -174,7 +173,7 @@ static void bar_pane_gps_close_save_cb(GenericDialog *UNUSED(gd), gpointer data)
                                                }
                                        }
                                }
-                       g_list_free(work);
+                       g_list_free(list);
 
                        if(count)
                                {
index 6895812..7c971c6 100644 (file)
@@ -314,14 +314,13 @@ static void bar_pane_keywords_write_config(GtkWidget *pane, GString *outstr, gin
        gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(pkd->keyword_treeview),
                                                                (bar_keyword_tree_get_expanded_cb), &path_expanded);
 
-       g_list_first(path_expanded);
-       while (path_expanded)
+       GList *work = g_list_first(path_expanded);
+       while (work)
                {
-               bar_pane_keywords_entry_write_config(static_cast<gchar *>(path_expanded->data), outstr, indent);
-               g_free(path_expanded->data);
-               path_expanded = path_expanded->next;
+               bar_pane_keywords_entry_write_config(static_cast<gchar *>(work->data), outstr, indent);
+               work = work->next;
                }
-       g_list_free(path_expanded);
+       g_list_free_full(path_expanded, g_free);
 
        indent--;
        WRITE_NL();
index db16dcc..2f69fa5 100644 (file)
@@ -1004,20 +1004,21 @@ static void dupe_match_unlink(DupeItem *a, DupeItem *b)
  */
 static void dupe_match_link_clear(DupeItem *parent, gboolean unlink_children)
 {
-       GList *work;
-
-       work = parent->group;
-       while (work)
+       if (unlink_children)
                {
-               auto dm = static_cast<DupeMatch *>(work->data);
-               work = work->next;
+               GList *work;
 
-               if (unlink_children) dupe_match_unlink_child(parent, dm->di);
+               work = parent->group;
+               while (work)
+                       {
+                       auto dm = static_cast<DupeMatch *>(work->data);
+                       work = work->next;
 
-               g_free(dm);
+                       dupe_match_unlink_child(parent, dm->di);
+                       }
                }
 
-       g_list_free(parent->group);
+       g_list_free_full(parent->group, g_free);
        parent->group = nullptr;
        parent->group_rank = 0.0;
 }
index 214ed70..b9ef757 100644 (file)
@@ -711,11 +711,12 @@ void file_data_dump()
                log_printf("%d", global_file_data_count);
                log_printf("%d", g_list_length(list));
 
-               while (list)
+               GList *work = list;
+               while (work)
                        {
-                       fd = static_cast<FileData *>(list->data);
+                       fd = static_cast<FileData *>(work->data);
                        log_printf("%-4d %s", fd->ref, fd->path);
-                       list = list->next;
+                       work = work->next;
                        }
 
                g_list_free(list);
@@ -1603,20 +1604,18 @@ GList *filelist_filter(GList *list, gboolean is_dir_list)
                {
                auto fd = static_cast<FileData *>(work->data);
                const gchar *name = fd->name;
+               GList *link = work;
+               work = work->next;
 
                if ((!options->file_filter.show_hidden_files && is_hidden_file(name)) ||
                    (!is_dir_list && !filter_name_exists(name)) ||
                    (is_dir_list && name[0] == '.' && (strcmp(name, GQ_CACHE_LOCAL_THUMB) == 0 ||
                                                       strcmp(name, GQ_CACHE_LOCAL_METADATA) == 0)) )
                        {
-                       GList *link = work;
-
                        list = g_list_remove_link(list, link);
                        file_data_unref(fd);
                        g_list_free(link);
                        }
-
-               work = work->next;
                }
 
        return list;
index 05f9db7..c473957 100644 (file)
@@ -167,10 +167,11 @@ static void vflist_store_clear(ViewFile *vf, gboolean unlock_files)
                {
                // unlock locked files in this directory
                filelist_read(vf->dir_fd, &files, nullptr);
-               while (files)
+               GList *work = files;
+               while (work)
                        {
-                       auto fd = static_cast<FileData *>(files->data);
-                       files = files->next;
+                       auto fd = static_cast<FileData *>(work->data);
+                       work = work->next;
                        file_data_unlock(fd);
                        file_data_unref(fd);  // undo the ref that got added in filelist_read
                        }