Stop using GSlice

It has been inofficially deprecated for years, is known to cause issues
with valgrind and potentially hides memory corruption.
Lets stop using it.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1473
This commit is contained in:
Robert Mader 2020-10-19 20:12:27 +02:00
parent d72da7d246
commit 22f691939c
12 changed files with 39 additions and 39 deletions

View File

@ -148,7 +148,7 @@ client_data_free (ClientData *data)
{ {
g_signal_handler_disconnect (data->client, data->backend_died_id); g_signal_handler_disconnect (data->client, data->backend_died_id);
g_object_unref (data->client); g_object_unref (data->client);
g_slice_free (ClientData, data); g_free (data);
} }
static void static void
@ -378,7 +378,7 @@ calendar_sources_connect_client_sync (CalendarSources *sources,
} }
else else
{ {
client_data = g_slice_new0 (ClientData); client_data = g_new0 (ClientData, 1);
client_data->client = E_CAL_CLIENT (g_object_ref (client)); client_data->client = E_CAL_CLIENT (g_object_ref (client));
client_data->backend_died_id = g_signal_connect (client, client_data->backend_died_id = g_signal_connect (client,
"backend-died", "backend-died",
@ -406,7 +406,7 @@ async_context_free (gpointer ptr)
if (ctx) if (ctx)
{ {
g_clear_object (&ctx->source); g_clear_object (&ctx->source);
g_slice_free (AsyncContext, ctx); g_free (ctx);
} }
} }
@ -446,7 +446,7 @@ calendar_sources_connect_client (CalendarSources *sources,
AsyncContext *ctx; AsyncContext *ctx;
g_autoptr (GTask) task = NULL; g_autoptr (GTask) task = NULL;
ctx = g_slice_new0 (AsyncContext); ctx = g_new0 (AsyncContext, 1);
ctx->source = g_object_ref (source); ctx->source = g_object_ref (source);
ctx->source_type = source_type; ctx->source_type = source_type;
ctx->wait_for_connected_seconds = wait_for_connected_seconds; ctx->wait_for_connected_seconds = wait_for_connected_seconds;

View File

@ -507,7 +507,7 @@ gtk_action_muxer_register_observer (GtkActionObservable *observable,
if (action == NULL) if (action == NULL)
{ {
action = g_slice_new (Action); action = g_new (Action, 1);
action->muxer = muxer; action->muxer = muxer;
action->fullname = g_strdup (name); action->fullname = g_strdup (name);
action->watchers = NULL; action->watchers = NULL;
@ -545,7 +545,7 @@ gtk_action_muxer_free_group (gpointer data)
g_object_unref (group->group); g_object_unref (group->group);
g_free (group->prefix); g_free (group->prefix);
g_slice_free (Group, group); g_free (group);
} }
static void static void
@ -560,7 +560,7 @@ gtk_action_muxer_free_action (gpointer data)
g_slist_free (action->watchers); g_slist_free (action->watchers);
g_free (action->fullname); g_free (action->fullname);
g_slice_free (Action, action); g_free (action);
} }
static void static void
@ -711,7 +711,7 @@ gtk_action_muxer_insert (GtkActionMuxer *muxer,
/* TODO: diff instead of ripout and replace */ /* TODO: diff instead of ripout and replace */
gtk_action_muxer_remove (muxer, prefix); gtk_action_muxer_remove (muxer, prefix);
group = g_slice_new (Group); group = g_new (Group, 1);
group->muxer = muxer; group->muxer = muxer;
group->group = g_object_ref (action_group); group->group = g_object_ref (action_group);
group->prefix = g_strdup (prefix); group->prefix = g_strdup (prefix);

View File

@ -86,7 +86,7 @@ invocation_data_new (GVariant *params,
{ {
InvocationData *ret; InvocationData *ret;
ret = g_slice_new0 (InvocationData); ret = g_new0 (InvocationData, 1);
ret->parameters = g_variant_ref (params); ret->parameters = g_variant_ref (params);
ret->invocation = g_object_ref (invocation); ret->invocation = g_object_ref (invocation);
@ -99,7 +99,7 @@ invocation_data_free (InvocationData *data)
g_variant_unref (data->parameters); g_variant_unref (data->parameters);
g_clear_object (&data->invocation); g_clear_object (&data->invocation);
g_slice_free (InvocationData, data); g_free (data);
} }
static void static void

View File

@ -58,7 +58,7 @@ cache_state_free (CacheState *state)
{ {
g_clear_pointer (&state->folders, g_hash_table_unref); g_clear_pointer (&state->folders, g_hash_table_unref);
g_list_free_full (state->app_infos, g_object_unref); g_list_free_full (state->app_infos, g_object_unref);
g_slice_free (CacheState, state); g_free (state);
} }
static CacheState * static CacheState *
@ -66,7 +66,7 @@ cache_state_new (void)
{ {
CacheState *state; CacheState *state;
state = g_slice_new0 (CacheState); state = g_new0 (CacheState, 1);
state->folders = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); state->folders = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
return g_steal_pointer (&state); return g_steal_pointer (&state);

View File

@ -1453,7 +1453,7 @@ create_running_state (ShellApp *app)
g_assert (app->running_state == NULL); g_assert (app->running_state == NULL);
app->running_state = g_slice_new0 (ShellAppRunningState); app->running_state = g_new0 (ShellAppRunningState, 1);
app->running_state->refcount = 1; app->running_state->refcount = 1;
app->running_state->workspace_switch_id = app->running_state->workspace_switch_id =
g_signal_connect (workspace_manager, "workspace-switched", g_signal_connect (workspace_manager, "workspace-switched",
@ -1527,7 +1527,7 @@ unref_running_state (ShellAppRunningState *state)
g_clear_object (&state->session); g_clear_object (&state->session);
g_clear_pointer (&state->unique_bus_name, g_free); g_clear_pointer (&state->unique_bus_name, g_free);
g_slice_free (ShellAppRunningState, state); g_free (state);
} }
/** /**

View File

@ -1581,7 +1581,7 @@ run_leisure_functions (gpointer data)
if (closure->notify) if (closure->notify)
closure->notify (closure->user_data); closure->notify (closure->user_data);
g_slice_free (LeisureClosure, closure); g_free (closure);
} }
g_slist_free (closures); g_slist_free (closures);
@ -1670,7 +1670,7 @@ shell_global_run_at_leisure (ShellGlobal *global,
gpointer user_data, gpointer user_data,
GDestroyNotify notify) GDestroyNotify notify)
{ {
LeisureClosure *closure = g_slice_new (LeisureClosure); LeisureClosure *closure = g_new (LeisureClosure, 1);
closure->func = func; closure->func = func;
closure->user_data = user_data; closure->user_data = user_data;
closure->notify = notify; closure->notify = notify;

View File

@ -81,7 +81,7 @@ shell_agent_request_free (gpointer data)
g_strfreev (request->hints); g_strfreev (request->hints);
g_clear_pointer (&request->entries, g_variant_dict_unref); g_clear_pointer (&request->entries, g_variant_dict_unref);
g_slice_free (ShellAgentRequest, request); g_free (request);
} }
static void static void
@ -360,7 +360,7 @@ shell_network_agent_get_secrets (NMSecretAgentOld *agent,
shell_agent_request_cancel (request); shell_agent_request_cancel (request);
} }
request = g_slice_new0 (ShellAgentRequest); request = g_new0 (ShellAgentRequest, 1);
request->self = g_object_ref (self); request->self = g_object_ref (self);
request->cancellable = g_cancellable_new (); request->cancellable = g_cancellable_new ();
request->connection = g_object_ref (connection); request->connection = g_object_ref (connection);
@ -617,7 +617,7 @@ keyring_request_free (KeyringRequest *r)
g_object_unref (r->self); g_object_unref (r->self);
g_object_unref (r->connection); g_object_unref (r->connection);
g_slice_free (KeyringRequest, r); g_free (r);
} }
static void static void
@ -765,7 +765,7 @@ shell_network_agent_save_secrets (NMSecretAgentOld *agent,
{ {
KeyringRequest *r; KeyringRequest *r;
r = g_slice_new (KeyringRequest); r = g_new (KeyringRequest, 1);
r->n_secrets = 0; r->n_secrets = 0;
r->self = g_object_ref (agent); r->self = g_object_ref (agent);
r->connection = g_object_ref (connection); r->connection = g_object_ref (connection);
@ -812,7 +812,7 @@ shell_network_agent_delete_secrets (NMSecretAgentOld *agent,
NMSettingConnection *s_con; NMSettingConnection *s_con;
const gchar *uuid; const gchar *uuid;
r = g_slice_new (KeyringRequest); r = g_new (KeyringRequest, 1);
r->n_secrets = 0; /* ignored by delete secrets calls */ r->n_secrets = 0; /* ignored by delete secrets calls */
r->self = g_object_ref (agent); r->self = g_object_ref (agent);
r->connection = g_object_ref (connection); r->connection = g_object_ref (connection);

View File

@ -259,7 +259,7 @@ define_event (ShellPerfLog *perf_log,
return NULL; return NULL;
} }
event = g_slice_new (ShellPerfEvent); event = g_new (ShellPerfEvent, 1);
event->id = perf_log->events->len; event->id = perf_log->events->len;
event->name = g_strdup (name); event->name = g_strdup (name);
@ -501,7 +501,7 @@ shell_perf_log_define_statistic (ShellPerfLog *perf_log,
if (event == NULL) if (event == NULL)
return; return;
statistic = g_slice_new (ShellPerfStatistic); statistic = g_new (ShellPerfStatistic, 1);
statistic->event = event; statistic->event = event;
statistic->initialized = FALSE; statistic->initialized = FALSE;
@ -598,7 +598,7 @@ shell_perf_log_add_statistics_callback (ShellPerfLog *perf_log,
gpointer user_data, gpointer user_data,
GDestroyNotify notify) GDestroyNotify notify)
{ {
ShellPerfStatisticsClosure *closure = g_slice_new (ShellPerfStatisticsClosure); ShellPerfStatisticsClosure *closure = g_new (ShellPerfStatisticsClosure, 1);
closure->callback = callback; closure->callback = callback;
closure->user_data = user_data; closure->user_data = user_data;

View File

@ -76,7 +76,7 @@ free_tray_icon (gpointer data)
0, 0, NULL, NULL, child); 0, 0, NULL, NULL, child);
g_object_unref (child->actor); g_object_unref (child->actor);
} }
g_slice_free (ShellTrayManagerChild, child); g_free (child);
} }
static void static void
@ -337,7 +337,7 @@ na_tray_icon_added (NaTrayManager *na_manager, GtkWidget *socket,
* the window we put it in match that as well */ * the window we put it in match that as well */
gtk_widget_set_visual (win, gtk_widget_get_visual (socket)); gtk_widget_set_visual (win, gtk_widget_get_visual (socket));
child = g_slice_new0 (ShellTrayManagerChild); child = g_new0 (ShellTrayManagerChild, 1);
child->manager = manager; child->manager = manager;
child->window = win; child->window = win;
child->socket = socket; child->socket = socket;

View File

@ -33,7 +33,7 @@ st_icon_colors_new (void)
{ {
StIconColors *colors; StIconColors *colors;
colors = g_slice_new0 (StIconColors); colors = g_new0 (StIconColors, 1);
colors->ref_count = 1; colors->ref_count = 1;
return colors; return colors;
@ -72,7 +72,7 @@ st_icon_colors_unref (StIconColors *colors)
g_return_if_fail (colors->ref_count > 0); g_return_if_fail (colors->ref_count > 0);
if (g_atomic_int_dec_and_test ((volatile int *)&colors->ref_count)) if (g_atomic_int_dec_and_test ((volatile int *)&colors->ref_count))
g_slice_free (StIconColors, colors); g_free (colors);
} }
/** /**

View File

@ -59,7 +59,7 @@ st_shadow_new (ClutterColor *color,
{ {
StShadow *shadow; StShadow *shadow;
shadow = g_slice_new (StShadow); shadow = g_new (StShadow, 1);
shadow->color = *color; shadow->color = *color;
shadow->xoffset = xoffset; shadow->xoffset = xoffset;
@ -105,7 +105,7 @@ st_shadow_unref (StShadow *shadow)
g_return_if_fail (shadow->ref_count > 0); g_return_if_fail (shadow->ref_count > 0);
if (g_atomic_int_dec_and_test (&shadow->ref_count)) if (g_atomic_int_dec_and_test (&shadow->ref_count))
g_slice_free (StShadow, shadow); g_free (shadow);
} }
/** /**
@ -210,7 +210,7 @@ st_shadow_helper_new (StShadow *shadow)
{ {
StShadowHelper *helper; StShadowHelper *helper;
helper = g_slice_new0 (StShadowHelper); helper = g_new0 (StShadowHelper, 1);
helper->shadow = st_shadow_ref (shadow); helper->shadow = st_shadow_ref (shadow);
return helper; return helper;
@ -255,7 +255,7 @@ st_shadow_helper_copy (StShadowHelper *helper)
{ {
StShadowHelper *copy; StShadowHelper *copy;
copy = g_slice_new (StShadowHelper); copy = g_new (StShadowHelper, 1);
*copy = *helper; *copy = *helper;
if (copy->pipeline) if (copy->pipeline)
cogl_object_ref (copy->pipeline); cogl_object_ref (copy->pipeline);
@ -277,7 +277,7 @@ st_shadow_helper_free (StShadowHelper *helper)
cogl_object_unref (helper->pipeline); cogl_object_unref (helper->pipeline);
st_shadow_unref (helper->shadow); st_shadow_unref (helper->shadow);
g_slice_free (StShadowHelper, helper); g_free (helper);
} }
/** /**

View File

@ -353,7 +353,7 @@ texture_load_data_free (gpointer p)
if (data->actors) if (data->actors)
g_slist_free_full (data->actors, (GDestroyNotify) g_object_unref); g_slist_free_full (data->actors, (GDestroyNotify) g_object_unref);
g_slice_free (AsyncTextureLoadData, data); g_free (data);
} }
/** /**
@ -807,7 +807,7 @@ st_texture_cache_free_bind (gpointer data)
StTextureCachePropertyBind *bind = data; StTextureCachePropertyBind *bind = data;
if (bind->weakref_active) if (bind->weakref_active)
g_object_weak_unref (G_OBJECT (bind->image), st_texture_cache_bind_weak_notify, bind); g_object_weak_unref (G_OBJECT (bind->image), st_texture_cache_bind_weak_notify, bind);
g_slice_free (StTextureCachePropertyBind, bind); g_free (bind);
} }
/** /**
@ -833,7 +833,7 @@ st_texture_cache_bind_cairo_surface_property (StTextureCache *cache,
gchar *notify_key; gchar *notify_key;
StTextureCachePropertyBind *bind; StTextureCachePropertyBind *bind;
bind = g_slice_new0 (StTextureCachePropertyBind); bind = g_new0 (StTextureCachePropertyBind, 1);
bind->cache = cache; bind->cache = cache;
bind->source = object; bind->source = object;
@ -930,7 +930,7 @@ ensure_request (StTextureCache *cache,
if (pending == NULL) if (pending == NULL)
{ {
/* Not cached and no pending request, create it */ /* Not cached and no pending request, create it */
*request = g_slice_new0 (AsyncTextureLoadData); *request = g_new0 (AsyncTextureLoadData, 1);
if (policy != ST_TEXTURE_CACHE_POLICY_NONE) if (policy != ST_TEXTURE_CACHE_POLICY_NONE)
g_hash_table_insert (cache->priv->outstanding_requests, g_strdup (key), *request); g_hash_table_insert (cache->priv->outstanding_requests, g_strdup (key), *request);
} }
@ -1192,7 +1192,7 @@ on_data_destroy (gpointer data)
g_object_unref (d->gfile); g_object_unref (d->gfile);
g_object_unref (d->actor); g_object_unref (d->actor);
g_object_unref (d->cancellable); g_object_unref (d->cancellable);
g_slice_free (AsyncImageData, d); g_free (d);
} }
static void static void
@ -1357,7 +1357,7 @@ st_texture_cache_load_sliced_image (StTextureCache *cache,
g_assert (paint_scale > 0); g_assert (paint_scale > 0);
g_assert (resource_scale > 0); g_assert (resource_scale > 0);
data = g_slice_new0 (AsyncImageData); data = g_new0 (AsyncImageData, 1);
data->grid_width = grid_width; data->grid_width = grid_width;
data->grid_height = grid_height; data->grid_height = grid_height;
data->paint_scale = paint_scale; data->paint_scale = paint_scale;