From 981c9ed2f155da2c8803da510ad81a2a8911e4e4 Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Tue, 6 Feb 2024 11:40:49 -0500 Subject: [PATCH] all: Stop using g_slice, fix a leak and remove an obsolete workaround. g_slice is deprecated as of glib 2.62 and is just a wrapper around the g_new/g_free family. --- libnemo-private/nemo-bookmark.c | 4 +- libnemo-private/nemo-clipboard-monitor.c | 4 +- libnemo-private/nemo-file-operations.c | 12 ++--- libnemo-private/nemo-file-undo-operations.c | 4 +- libnemo-private/nemo-file-utilities.c | 8 +-- libnemo-private/nemo-icon-container.c | 4 +- libnemo-private/nemo-icon-info.c | 9 ++-- libnemo-private/nemo-job-queue.c | 4 +- libnemo-private/nemo-search-engine-advanced.c | 4 +- libnemo-private/nemo-search-engine.c | 4 +- src/nemo-action-config-widget.c | 4 +- src/nemo-desktop-manager.c | 4 +- src/nemo-extension-config-widget.c | 4 +- src/nemo-places-sidebar.c | 4 +- src/nemo-progress-ui-handler.c | 4 +- src/nemo-script-config-widget.c | 5 +- src/nemo-view-dnd.c | 4 +- src/nemo-window-slot-dnd.c | 4 +- src/nemo-window-slot.c | 4 +- src/nemo-window.c | 49 ++----------------- 20 files changed, 51 insertions(+), 92 deletions(-) diff --git a/libnemo-private/nemo-bookmark.c b/libnemo-private/nemo-bookmark.c index 8dc57aeba..879fd806a 100644 --- a/libnemo-private/nemo-bookmark.c +++ b/libnemo-private/nemo-bookmark.c @@ -829,7 +829,7 @@ nemo_bookmark_get_current_metadata (NemoBookmark *bookmark) NemoBookmarkMetadata * nemo_bookmark_metadata_new (void) { - NemoBookmarkMetadata *meta = g_slice_new0 (NemoBookmarkMetadata); + NemoBookmarkMetadata *meta = g_new0 (NemoBookmarkMetadata, 1); return meta; } @@ -873,5 +873,5 @@ nemo_bookmark_metadata_free (NemoBookmarkMetadata *metadata) g_free (metadata->bookmark_name); g_strfreev (metadata->emblems); - g_slice_free (NemoBookmarkMetadata, metadata); + g_free (metadata); } diff --git a/libnemo-private/nemo-clipboard-monitor.c b/libnemo-private/nemo-clipboard-monitor.c index cfbb1b7ac..697207e5b 100644 --- a/libnemo-private/nemo-clipboard-monitor.c +++ b/libnemo-private/nemo-clipboard-monitor.c @@ -101,7 +101,7 @@ nemo_clipboard_info_new (GList *files, { NemoClipboardInfo *info; - info = g_slice_new0 (NemoClipboardInfo); + info = g_new0 (NemoClipboardInfo, 1); info->files = nemo_file_list_copy (files); info->cut = cut; @@ -128,7 +128,7 @@ nemo_clipboard_info_free (NemoClipboardInfo *info) { nemo_file_list_free (info->files); - g_slice_free (NemoClipboardInfo, info); + g_free (info); } static void diff --git a/libnemo-private/nemo-file-operations.c b/libnemo-private/nemo-file-operations.c index 8b107dbcc..05bf17a29 100644 --- a/libnemo-private/nemo-file-operations.c +++ b/libnemo-private/nemo-file-operations.c @@ -4328,13 +4328,13 @@ run_conflict_dialog (CommonJob *job, g_timer_stop (job->time); - data = g_slice_new0 (ConflictDialogData); + data = g_new0 (ConflictDialogData, 1); data->parent = job->parent_window; data->src = src; data->dest = dest; data->dest_dir = dest_dir; - resp_data = g_slice_new0 (ConflictResponseData); + resp_data = g_new0 (ConflictResponseData, 1); resp_data->new_name = NULL; data->resp_data = resp_data; @@ -4345,7 +4345,7 @@ run_conflict_dialog (CommonJob *job, NULL); nemo_progress_info_resume (job->progress); - g_slice_free (ConflictDialogData, data); + g_free (data); g_timer_continue (job->time); @@ -4356,7 +4356,7 @@ static void conflict_response_data_free (ConflictResponseData *data) { g_free (data->new_name); - g_slice_free (ConflictResponseData, data); + g_free (data); } static GFile * @@ -6211,7 +6211,7 @@ callback_for_move_to_trash (GHashTable *debuting_uris, { if (data->real_callback) data->real_callback (debuting_uris, !user_cancelled, data->real_data); - g_slice_free (MoveTrashCBData, data); + g_free (data); } void @@ -6286,7 +6286,7 @@ nemo_file_operations_copy_move (const GList *item_uris, if (g_file_has_uri_scheme (dest, "trash")) { MoveTrashCBData *cb_data; - cb_data = g_slice_new0 (MoveTrashCBData); + cb_data = g_new0 (MoveTrashCBData, 1); cb_data->real_callback = done_callback; cb_data->real_data = done_callback_data; diff --git a/libnemo-private/nemo-file-undo-operations.c b/libnemo-private/nemo-file-undo-operations.c index 95e7831bd..ababc4fee 100644 --- a/libnemo-private/nemo-file-undo-operations.c +++ b/libnemo-private/nemo-file-undo-operations.c @@ -241,7 +241,7 @@ typedef struct { static void file_undo_info_op_res_free (gpointer data) { - g_slice_free (FileUndoInfoOpRes, data); + g_free (data); } gboolean @@ -279,7 +279,7 @@ file_undo_info_complete_apply (NemoFileUndoInfo *self, gboolean success, gboolean user_cancel) { - FileUndoInfoOpRes *op_res = g_slice_new0 (FileUndoInfoOpRes); + FileUndoInfoOpRes *op_res = g_new0 (FileUndoInfoOpRes, 1); op_res->user_cancel = user_cancel; op_res->success = success; diff --git a/libnemo-private/nemo-file-utilities.c b/libnemo-private/nemo-file-utilities.c index 69c0a6488..c63eaf698 100644 --- a/libnemo-private/nemo-file-utilities.c +++ b/libnemo-private/nemo-file-utilities.c @@ -1318,7 +1318,7 @@ ensure_dirs_task_ready_cb (GObject *_source, g_list_free (original_dirs); g_hash_table_unref (data->original_dirs_hash); - g_slice_free (RestoreFilesData, data); + g_free (data); } static void @@ -1351,7 +1351,7 @@ restore_files_ensure_parent_directories (GHashTable *original_dirs_hash, RestoreFilesData *data; GTask *ensure_dirs_task; - data = g_slice_new0 (RestoreFilesData); + data = g_new0 (RestoreFilesData, 1); data->parent_window = parent_window; data->original_dirs_hash = g_hash_table_ref (original_dirs_hash); @@ -1417,7 +1417,7 @@ get_types_cb (GObject *source_object, data->callback ((const char **) types, data->user_data); } g_strfreev (types); - g_slice_free (GetContentTypesData, data); + g_free (data); } void @@ -1444,7 +1444,7 @@ nemo_get_x_content_types_for_mount_async (GMount *mount, return; } - data = g_slice_new0 (GetContentTypesData); + data = g_new0 (GetContentTypesData, 1); data->callback = callback; data->user_data = user_data; diff --git a/libnemo-private/nemo-icon-container.c b/libnemo-private/nemo-icon-container.c index 617a047c9..d56c4314f 100644 --- a/libnemo-private/nemo-icon-container.c +++ b/libnemo-private/nemo-icon-container.c @@ -2781,7 +2781,7 @@ finalize (GObject *object) g_source_remove (details->a11y_item_action_idle_handler); } - g_slice_free (NemoViewLayoutConstants, details->view_constants); + g_free (details->view_constants); g_list_free (details->current_selection); g_free(details); @@ -4920,7 +4920,7 @@ nemo_icon_container_init (NemoIconContainer *container) details->fixed_text_height = -1; - details->view_constants = g_slice_new0 (NemoViewLayoutConstants); + details->view_constants = g_new0 (NemoViewLayoutConstants, 1); container->details = details; diff --git a/libnemo-private/nemo-icon-info.c b/libnemo-private/nemo-icon-info.c index 303377dea..2ecf4df19 100644 --- a/libnemo-private/nemo-icon-info.c +++ b/libnemo-private/nemo-icon-info.c @@ -61,8 +61,7 @@ nemo_icon_info_free (NemoIconInfo *icon) } g_free (icon->icon_name); - - g_slice_free (NemoIconInfo, icon); + g_free (icon); } NemoIconInfo * @@ -106,7 +105,7 @@ nemo_icon_info_create (void) { NemoIconInfo *icon; - icon = g_slice_new0 (NemoIconInfo); + icon = g_new0 (NemoIconInfo, 1); icon->last_use_time = g_get_monotonic_time (); icon->sole_owner = TRUE; @@ -270,7 +269,7 @@ icon_key_new (GIcon *icon, int size) { IconKey *key; - key = g_slice_new (IconKey); + key = g_new0 (IconKey, 1); key->icon = g_object_ref (icon); key->size = size; @@ -281,7 +280,7 @@ static void icon_key_free (IconKey *key) { g_object_unref (key->icon); - g_slice_free (IconKey, key); + g_free (key); } NemoIconInfo * diff --git a/libnemo-private/nemo-job-queue.c b/libnemo-private/nemo-job-queue.c index 366b52540..b3868e91e 100644 --- a/libnemo-private/nemo-job-queue.c +++ b/libnemo-private/nemo-job-queue.c @@ -163,7 +163,7 @@ job_finished_cb (NemoJobQueue *self, self->priv->running_jobs = g_list_remove (self->priv->running_jobs, job); self->priv->queued_jobs = g_list_remove (self->priv->queued_jobs, job); - g_slice_free (Job, job); + g_free (job); nemo_job_queue_start_next_job (self); } @@ -189,7 +189,7 @@ nemo_job_queue_add_new_job (NemoJobQueue *self, return; } - Job *new_job = g_slice_new0 (Job); + Job *new_job = g_new0 (Job, 1); new_job->job_func = job_func; new_job->user_data = user_data; new_job->cancellable = cancellable; diff --git a/libnemo-private/nemo-search-engine-advanced.c b/libnemo-private/nemo-search-engine-advanced.c index e06062349..4e7499cec 100644 --- a/libnemo-private/nemo-search-engine-advanced.c +++ b/libnemo-private/nemo-search-engine-advanced.c @@ -92,7 +92,7 @@ static void search_helper_free (SearchHelper *helper) { g_free (helper->exec_format); - g_slice_free (SearchHelper, helper); + g_free (helper); } static GList * @@ -220,7 +220,7 @@ process_search_helper_file (const gchar *path) DEBUG ("Replacing existing nemo search_helper for '%s' with %s based on priority.", mime_type, path); } - helper = g_slice_new0 (SearchHelper); + helper = g_new0 (SearchHelper, 1); helper->exec_format = g_strdup (exec_format); helper->priority = priority; diff --git a/libnemo-private/nemo-search-engine.c b/libnemo-private/nemo-search-engine.c index 278d4b6b1..ed75e9813 100644 --- a/libnemo-private/nemo-search-engine.c +++ b/libnemo-private/nemo-search-engine.c @@ -180,7 +180,7 @@ static GHashTable *fsr_accounting_table = NULL; FileSearchResult * file_search_result_new (gchar *uri, gchar *snippet) { - FileSearchResult *ret = g_slice_new0 (FileSearchResult); + FileSearchResult *ret = g_new0 (FileSearchResult, 1); ret->uri = uri; ret->snippet = snippet; @@ -215,7 +215,7 @@ file_search_result_free (FileSearchResult *res) g_free (res->uri); g_free (res->snippet); - g_slice_free (FileSearchResult, res); + g_free (res); } void diff --git a/src/nemo-action-config-widget.c b/src/nemo-action-config-widget.c index 442432d7b..4b7f66d09 100644 --- a/src/nemo-action-config-widget.c +++ b/src/nemo-action-config-widget.c @@ -35,7 +35,7 @@ action_proxy_free (ActionProxy *proxy) g_clear_pointer (&proxy->stock_id, g_free); g_clear_pointer (&proxy->icon_name, g_free); g_clear_pointer (&proxy->filename, g_free); - g_slice_free (ActionProxy, proxy); + g_free (proxy); } static GtkWidget * @@ -114,7 +114,7 @@ make_action_proxy (const gchar *filename, const gchar *fullpath) } } - ActionProxy *proxy = g_slice_new0 (ActionProxy); + ActionProxy *proxy = g_new0 (ActionProxy, 1); gchar *name = g_key_file_get_locale_string (key_file, ACTION_FILE_GROUP, diff --git a/src/nemo-desktop-manager.c b/src/nemo-desktop-manager.c index fdda91a10..86928e5b9 100644 --- a/src/nemo-desktop-manager.c +++ b/src/nemo-desktop-manager.c @@ -101,7 +101,7 @@ free_info (DesktopInfo *info) g_return_if_fail (info != NULL); g_clear_pointer (&info->window, gtk_widget_destroy); - g_slice_free (DesktopInfo, info); + g_free (info); } static RunState @@ -308,7 +308,7 @@ create_new_desktop_window (NemoDesktopManager *manager, FETCH_PRIV (manager); GtkWidget *window; - DesktopInfo *info = g_slice_new0 (DesktopInfo); + DesktopInfo *info = g_new0 (DesktopInfo, 1); info->monitor_num = monitor; info->shows_desktop = show_desktop; diff --git a/src/nemo-extension-config-widget.c b/src/nemo-extension-config-widget.c index fa249d8ec..9323326d8 100644 --- a/src/nemo-extension-config-widget.c +++ b/src/nemo-extension-config-widget.c @@ -30,7 +30,7 @@ extension_proxy_free (ExtensionProxy *proxy) g_clear_pointer (&proxy->display_name, g_free); g_clear_pointer (&proxy->desc, g_free); g_clear_pointer (&proxy->config_exec, g_free); - g_slice_free (ExtensionProxy, proxy); + g_free (proxy); } static void @@ -160,7 +160,7 @@ detect_extensions (NemoExtensionConfigWidget *widget) guint i; for (i = 0; i < g_strv_length (lines); i++) { if (g_str_has_prefix (lines[i], LINE_PREFIX)) { - ExtensionProxy *p = g_slice_new0 (ExtensionProxy); + ExtensionProxy *p = g_new0 (ExtensionProxy, 1); gchar **split = g_strsplit (lines[i] + LINE_PREFIX_LEN, ":::", -1); gint len = g_strv_length (split); diff --git a/src/nemo-places-sidebar.c b/src/nemo-places-sidebar.c index f7db112b7..7a0feeebb 100644 --- a/src/nemo-places-sidebar.c +++ b/src/nemo-places-sidebar.c @@ -404,7 +404,7 @@ new_place_info (PlaceType place_type, gint df_percent, gboolean show_df_percent) { - PlaceInfo *info = g_slice_new0 (PlaceInfo); + PlaceInfo *info = g_new0 (PlaceInfo, 1); info->place_type = place_type; info->section_type = section_type; @@ -433,7 +433,7 @@ free_place_info (PlaceInfo *info) g_clear_object (&info->mount); g_free (info->tooltip); - g_slice_free (PlaceInfo, info); + g_free (info); } static GtkTreeIter diff --git a/src/nemo-progress-ui-handler.c b/src/nemo-progress-ui-handler.c index 227866438..0787a68a7 100644 --- a/src/nemo-progress-ui-handler.c +++ b/src/nemo-progress-ui-handler.c @@ -385,7 +385,7 @@ timeout_data_free (TimeoutData *data) g_clear_object (&data->self); g_clear_object (&data->info); - g_slice_free (TimeoutData, data); + g_free (data); } static TimeoutData * @@ -394,7 +394,7 @@ timeout_data_new (NemoProgressUIHandler *self, { TimeoutData *retval; - retval = g_slice_new0 (TimeoutData); + retval = g_new0 (TimeoutData, 1); retval->self = g_object_ref (self); retval->info = g_object_ref (info); diff --git a/src/nemo-script-config-widget.c b/src/nemo-script-config-widget.c index 107a2e123..e352033c9 100644 --- a/src/nemo-script-config-widget.c +++ b/src/nemo-script-config-widget.c @@ -26,7 +26,8 @@ typedef struct { static void script_proxy_free (ScriptProxy *proxy) { - g_clear_pointer (&proxy->name, g_free); + g_free (proxy->name); + g_free (proxy); } static GtkWidget * @@ -113,7 +114,7 @@ populate_from_directory (NemoScriptConfigWidget *widget, const gchar *path) continue; } - ScriptProxy *p = g_slice_new0 (ScriptProxy); + ScriptProxy *p = g_new0 (ScriptProxy, 1); p->name = g_strdup (name); p->widget = widget; diff --git a/src/nemo-view-dnd.c b/src/nemo-view-dnd.c index 3d45c77f8..aae11495c 100644 --- a/src/nemo-view-dnd.c +++ b/src/nemo-view-dnd.c @@ -147,7 +147,7 @@ handle_netscape_url_drop_link_cb (GObject *source_object, g_free (data->target_uri); g_object_unref (data->view); - g_slice_free (NetscapeUrlDropLink, data); + g_free (data); } void @@ -220,7 +220,7 @@ nemo_view_handle_netscape_url_drop (NemoView *view, if (g_strcmp0 (link_name, NULL) != 0) { NetscapeUrlDropLink *data; - data = g_slice_new0 (NetscapeUrlDropLink); + data = g_new0 (NetscapeUrlDropLink, 1); data->link_name = link_name; data->point.x = x; data->point.y = y; diff --git a/src/nemo-window-slot-dnd.c b/src/nemo-window-slot-dnd.c index 201c62087..9183db0e5 100644 --- a/src/nemo-window-slot-dnd.c +++ b/src/nemo-window-slot-dnd.c @@ -137,7 +137,7 @@ drag_info_free (gpointer user_data) g_clear_object (&drag_info->target_slot); g_clear_pointer (&drag_info->desktop_dnd_source_fs, g_free); - g_slice_free (NemoDragSlotProxyInfo, drag_info); + g_free (drag_info); } static void @@ -332,7 +332,7 @@ nemo_drag_slot_proxy_init (GtkWidget *widget, g_assert (GTK_IS_WIDGET (widget)); - drag_info = g_slice_new0 (NemoDragSlotProxyInfo); + drag_info = g_new0 (NemoDragSlotProxyInfo, 1); g_object_set_data_full (G_OBJECT (widget), "drag-slot-proxy-data", drag_info, drag_info_free); diff --git a/src/nemo-window-slot.c b/src/nemo-window-slot.c index 77cb164d3..d6dfe880d 100644 --- a/src/nemo-window-slot.c +++ b/src/nemo-window-slot.c @@ -710,7 +710,7 @@ set_status_data_free (gpointer data) g_free (status_data->status); - g_slice_free (SetStatusData, data); + g_free (data); } static gboolean @@ -742,7 +742,7 @@ set_floating_bar_status (NemoWindowSlot *slot, "gtk-double-click-time", &double_click_time, NULL); - status_data = g_slice_new0 (SetStatusData); + status_data = g_new0 (SetStatusData, 1); status_data->status = g_strdup (status); status_data->slot = slot; diff --git a/src/nemo-window.c b/src/nemo-window.c index 655ed016f..3abb8f964 100644 --- a/src/nemo-window.c +++ b/src/nemo-window.c @@ -2326,58 +2326,17 @@ nemo_window_set_ignore_meta_zoom_level (NemoWindow *window, gint level) window->details->ignore_meta_zoom_level = level; } -/* FIXME: - * - * Remove this and just use g_list_copy_deep - * when we no longer need to support GLib < 2.34 - * - */ - -static GList * -list_copy_deep (GList *list, GCopyFunc func, gpointer user_data) -{ - GList *new_list = NULL; - - if (list) - { - GList *last; - - new_list = g_slice_new (GList); - if (func) - new_list->data = func (list->data, user_data); - else - new_list->data = list->data; - new_list->prev = NULL; - last = new_list; - list = list->next; - while (list) - { - last->next = g_slice_new (GList); - last->next->prev = last; - last = last->next; - if (func) - last->data = func (list->data, user_data); - else - last->data = list->data; - list = list->next; - } - last->next = NULL; - } - - return new_list; -} - GList * nemo_window_get_ignore_meta_visible_columns (NemoWindow *window) { - return list_copy_deep (window->details->ignore_meta_visible_columns, (GCopyFunc) g_strdup, NULL); + return g_list_copy_deep (window->details->ignore_meta_visible_columns, (GCopyFunc) g_strdup, NULL); } void nemo_window_set_ignore_meta_visible_columns (NemoWindow *window, GList *list) { GList *old = window->details->ignore_meta_visible_columns; - window->details->ignore_meta_visible_columns = list != NULL ? list_copy_deep (list, (GCopyFunc) g_strdup, NULL) : + window->details->ignore_meta_visible_columns = list != NULL ? g_list_copy_deep (list, (GCopyFunc) g_strdup, NULL) : NULL; if (old != NULL) g_list_free_full (old, g_free); @@ -2386,14 +2345,14 @@ nemo_window_set_ignore_meta_visible_columns (NemoWindow *window, GList *list) GList * nemo_window_get_ignore_meta_column_order (NemoWindow *window) { - return list_copy_deep (window->details->ignore_meta_column_order, (GCopyFunc) g_strdup, NULL); + return g_list_copy_deep (window->details->ignore_meta_column_order, (GCopyFunc) g_strdup, NULL); } void nemo_window_set_ignore_meta_column_order (NemoWindow *window, GList *list) { GList *old = window->details->ignore_meta_column_order; - window->details->ignore_meta_column_order = list != NULL ? list_copy_deep (list, (GCopyFunc) g_strdup, NULL) : + window->details->ignore_meta_column_order = list != NULL ? g_list_copy_deep (list, (GCopyFunc) g_strdup, NULL) : NULL; if (old != NULL) g_list_free_full (old, g_free);