iface-modem-messaging: refactor memory management in handlers

Use g_auto* helpers where needed, and switch to use the slice
allocator for the handler operation contexts.
This commit is contained in:
Aleksander Morgado
2022-11-30 13:15:31 +00:00
parent 74441e8549
commit a962d63179

View File

@@ -156,7 +156,7 @@ handle_delete_context_free (HandleDeleteContext *ctx)
g_object_unref (ctx->invocation); g_object_unref (ctx->invocation);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_free (ctx->path); g_free (ctx->path);
g_free (ctx); g_slice_free (HandleDeleteContext, ctx);
} }
static void static void
@@ -170,7 +170,6 @@ handle_delete_ready (MMSmsList *list,
g_dbus_method_invocation_take_error (ctx->invocation, error); g_dbus_method_invocation_take_error (ctx->invocation, error);
else else
mm_gdbus_modem_messaging_complete_delete (ctx->skeleton, ctx->invocation); mm_gdbus_modem_messaging_complete_delete (ctx->skeleton, ctx->invocation);
handle_delete_context_free (ctx); handle_delete_context_free (ctx);
} }
@@ -179,7 +178,7 @@ handle_delete_auth_ready (MMBaseModem *self,
GAsyncResult *res, GAsyncResult *res,
HandleDeleteContext *ctx) HandleDeleteContext *ctx)
{ {
MMSmsList *list = NULL; g_autoptr(MMSmsList) list = NULL;
GError *error = NULL; GError *error = NULL;
if (!mm_base_modem_authorize_finish (self, res, &error)) { if (!mm_base_modem_authorize_finish (self, res, &error)) {
@@ -216,7 +215,6 @@ handle_delete_auth_ready (MMBaseModem *self,
ctx->path, ctx->path,
(GAsyncReadyCallback)handle_delete_ready, (GAsyncReadyCallback)handle_delete_ready,
ctx); ctx);
g_object_unref (list);
} }
static gboolean static gboolean
@@ -227,7 +225,7 @@ handle_delete (MmGdbusModemMessaging *skeleton,
{ {
HandleDeleteContext *ctx; HandleDeleteContext *ctx;
ctx = g_new (HandleDeleteContext, 1); ctx = g_slice_new0 (HandleDeleteContext);
ctx->skeleton = g_object_ref (skeleton); ctx->skeleton = g_object_ref (skeleton);
ctx->invocation = g_object_ref (invocation); ctx->invocation = g_object_ref (invocation);
ctx->self = g_object_ref (self); ctx->self = g_object_ref (self);
@@ -257,7 +255,7 @@ handle_create_context_free (HandleCreateContext *ctx)
g_object_unref (ctx->invocation); g_object_unref (ctx->invocation);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_variant_unref (ctx->dictionary); g_variant_unref (ctx->dictionary);
g_free (ctx); g_slice_free (HandleCreateContext, ctx);
} }
static void static void
@@ -265,10 +263,10 @@ handle_create_auth_ready (MMBaseModem *self,
GAsyncResult *res, GAsyncResult *res,
HandleCreateContext *ctx) HandleCreateContext *ctx)
{ {
MMSmsList *list = NULL;
GError *error = NULL; GError *error = NULL;
MMSmsProperties *properties; g_autoptr(MMSmsList) list = NULL;
MMBaseSms *sms; g_autoptr(MMSmsProperties) properties = NULL;
g_autoptr(MMBaseSms) sms = NULL;
if (!mm_base_modem_authorize_finish (self, res, &error)) { if (!mm_base_modem_authorize_finish (self, res, &error)) {
g_dbus_method_invocation_take_error (ctx->invocation, error); g_dbus_method_invocation_take_error (ctx->invocation, error);
@@ -291,11 +289,8 @@ handle_create_auth_ready (MMBaseModem *self,
return; return;
} }
sms = mm_base_sms_new_from_properties (MM_BASE_MODEM (self), sms = mm_base_sms_new_from_properties (MM_BASE_MODEM (self), properties, &error);
properties,
&error);
if (!sms) { if (!sms) {
g_object_unref (properties);
g_dbus_method_invocation_take_error (ctx->invocation, error); g_dbus_method_invocation_take_error (ctx->invocation, error);
handle_create_context_free (ctx); handle_create_context_free (ctx);
return; return;
@@ -305,8 +300,6 @@ handle_create_auth_ready (MMBaseModem *self,
MM_IFACE_MODEM_MESSAGING_SMS_LIST, &list, MM_IFACE_MODEM_MESSAGING_SMS_LIST, &list,
NULL); NULL);
if (!list) { if (!list) {
g_object_unref (properties);
g_object_unref (sms);
g_dbus_method_invocation_return_error (ctx->invocation, g_dbus_method_invocation_return_error (ctx->invocation,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE, MM_CORE_ERROR_WRONG_STATE,
@@ -322,11 +315,6 @@ handle_create_auth_ready (MMBaseModem *self,
mm_gdbus_modem_messaging_complete_create (ctx->skeleton, mm_gdbus_modem_messaging_complete_create (ctx->skeleton,
ctx->invocation, ctx->invocation,
mm_base_sms_get_path (sms)); mm_base_sms_get_path (sms));
g_object_unref (sms);
g_object_unref (properties);
g_object_unref (list);
handle_create_context_free (ctx); handle_create_context_free (ctx);
} }
@@ -338,7 +326,7 @@ handle_create (MmGdbusModemMessaging *skeleton,
{ {
HandleCreateContext *ctx; HandleCreateContext *ctx;
ctx = g_new (HandleCreateContext, 1); ctx = g_slice_new0 (HandleCreateContext);
ctx->skeleton = g_object_ref (skeleton); ctx->skeleton = g_object_ref (skeleton);
ctx->invocation = g_object_ref (invocation); ctx->invocation = g_object_ref (invocation);
ctx->self = g_object_ref (self); ctx->self = g_object_ref (self);
@@ -359,8 +347,8 @@ handle_list (MmGdbusModemMessaging *skeleton,
GDBusMethodInvocation *invocation, GDBusMethodInvocation *invocation,
MMIfaceModemMessaging *self) MMIfaceModemMessaging *self)
{ {
GStrv paths; g_auto(GStrv) paths = NULL;
MMSmsList *list = NULL; g_autoptr(MMSmsList) list = NULL;
if (mm_iface_modem_abort_invocation_if_state_not_reached (MM_IFACE_MODEM (self), if (mm_iface_modem_abort_invocation_if_state_not_reached (MM_IFACE_MODEM (self),
invocation, invocation,
@@ -382,8 +370,6 @@ handle_list (MmGdbusModemMessaging *skeleton,
mm_gdbus_modem_messaging_complete_list (skeleton, mm_gdbus_modem_messaging_complete_list (skeleton,
invocation, invocation,
(const gchar *const *)paths); (const gchar *const *)paths);
g_strfreev (paths);
g_object_unref (list);
return TRUE; return TRUE;
} }