Fix coding errors
authorColin Clark <colin.clark@cclark.uk>
Wed, 14 Jun 2023 09:52:07 +0000 (10:52 +0100)
committerColin Clark <colin.clark@cclark.uk>
Wed, 14 Jun 2023 09:52:07 +0000 (10:52 +0100)
Fix "Use of memory after it is freed" errors identified by clang-tidy

src/bar-keywords.cc
src/desktop-file.cc
src/filedata.cc

index de535f5..2fed208 100644 (file)
@@ -1843,11 +1843,11 @@ static void autocomplete_keywords_list_load(const gchar *path)
 
        pathl = path_from_utf8(path);
        f = fopen(pathl, "r");
-       g_free(pathl);
 
        if (!f)
                {
                log_printf("Warning: keywords file %s not loaded", pathl);
+               g_free(pathl);
                return;
                }
 
@@ -1857,9 +1857,12 @@ static void autocomplete_keywords_list_load(const gchar *path)
                {
                fclose(f);
                log_printf("Warning: keywords file %s not loaded", pathl);
+               g_free(pathl);
                return;
                }
 
+       g_free(pathl);
+
        while (fgets(s_buf, sizeof(s_buf), f))
                {
                if (s_buf[0]=='#') continue;
index 4d853d1..349021f 100644 (file)
@@ -496,8 +496,8 @@ static void plugin_disable_cb(GtkCellRendererToggle *UNUSED(renderer), gchar *pa
 
                        if (haystack && strcmp(haystack, path) == 0)
                                {
-                               g_free(haystack);
                                options->disabled_plugins = g_list_remove(options->disabled_plugins, haystack);
+                               g_free(haystack);
                                }
 
                        list = list->next;
index c218ee6..3b33553 100644 (file)
@@ -3215,8 +3215,8 @@ gboolean file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data
                if (nd->func == func && nd->data == data)
                        {
                        notify_func_list = g_list_delete_link(notify_func_list, work);
-                       g_free(nd);
                        DEBUG_2("Notify func unregistered: %p", (void *)nd);
+                       g_free(nd);
                        return TRUE;
                        }
                work = work->next;