[PATCH] iface-modem: use g_new0 instead of g_slice_new0 to allocate context
Ben Chan
benchan at chromium.org
Fri Jun 30 13:27:07 UTC 2017
By using g_new0 instead of g_slice_new0 to allocate certain context
structs, we can simply use g_free as GDestroyNotify in
g_task_set_task_data and get rid of those functions that solely wrap the
g_slice_free call.
---
src/mm-iface-modem.c | 20 ++++----------------
1 file changed, 4 insertions(+), 16 deletions(-)
diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c
index a8e60470..cd462a38 100644
--- a/src/mm-iface-modem.c
+++ b/src/mm-iface-modem.c
@@ -95,12 +95,6 @@ typedef struct {
} WaitForFinalStateContext;
static void
-wait_for_final_state_context_free (WaitForFinalStateContext *ctx)
-{
- g_slice_free (WaitForFinalStateContext, ctx);
-}
-
-static void
wait_for_final_state_context_complete (GTask *task,
MMModemState state,
GError *error)
@@ -220,10 +214,10 @@ mm_iface_modem_wait_for_final_state (MMIfaceModem *self,
/* Otherwise, we'll need to wait for the exact one we want */
}
- ctx = g_slice_new0 (WaitForFinalStateContext);
+ ctx = g_new0 (WaitForFinalStateContext, 1);
ctx->final_state = final_state;
- g_task_set_task_data (task, ctx, (GDestroyNotify)wait_for_final_state_context_free);
+ g_task_set_task_data (task, ctx, g_free);
/* Want to get notified when modem state changes */
ctx->state_changed_id = g_signal_connect (self,
@@ -246,12 +240,6 @@ typedef struct {
guint pin_check_timeout_id;
} InternalLoadUnlockRequiredContext;
-static void
-internal_load_unlock_required_context_free (InternalLoadUnlockRequiredContext *ctx)
-{
- g_slice_free (InternalLoadUnlockRequiredContext, ctx);
-}
-
static MMModemLock
internal_load_unlock_required_finish (MMIfaceModem *self,
GAsyncResult *res,
@@ -365,10 +353,10 @@ internal_load_unlock_required (MMIfaceModem *self,
InternalLoadUnlockRequiredContext *ctx;
GTask *task;
- ctx = g_slice_new0 (InternalLoadUnlockRequiredContext);
+ ctx = g_new0 (InternalLoadUnlockRequiredContext, 1);
task = g_task_new (self, NULL, callback, user_data);
- g_task_set_task_data (task, ctx, (GDestroyNotify)internal_load_unlock_required_context_free);
+ g_task_set_task_data (task, ctx, g_free);
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->load_unlock_required ||
!MM_IFACE_MODEM_GET_INTERFACE (self)->load_unlock_required_finish) {
--
2.13.2
More information about the ModemManager-devel
mailing list