mm-origin: Ensure objects stay alive during async operations

This commit is contained in:
Evangelos Ribeiro Tzaras
2023-01-19 11:53:06 +01:00
parent 0f9a89aa3b
commit 72a85d62fa

View File

@@ -393,6 +393,7 @@ delete_call_cb (MMModemVoice *voice,
} }
g_free (data->path); g_free (data->path);
g_object_unref (data->self);
g_free (data); g_free (data);
} }
@@ -407,7 +408,7 @@ delete_call (CallsMMOrigin *self,
path = calls_mm_call_get_object_path (call); path = calls_mm_call_get_object_path (call);
data = g_new0 (struct CallsMMOriginDeleteCallData, 1); data = g_new0 (struct CallsMMOriginDeleteCallData, 1);
data->self = self; data->self = g_object_ref (self);
data->path = g_strdup (path); data->path = g_strdup (path);
mm_modem_voice_delete_call (self->voice, mm_modem_voice_delete_call (self->voice,
@@ -516,6 +517,7 @@ call_added_list_calls_cb (MMModemVoice *voice,
} }
g_free (data->path); g_free (data->path);
g_object_unref (data->self);
g_free (data); g_free (data);
} }
@@ -534,7 +536,7 @@ call_added_cb (MMModemVoice *voice,
} }
data = g_new0 (struct CallsMMOriginCallAddedData, 1); data = g_new0 (struct CallsMMOriginCallAddedData, 1);
data->self = self; data->self = g_object_ref (self);
data->path = g_strdup (path); data->path = g_strdup (path);
mm_modem_voice_list_calls (voice, mm_modem_voice_list_calls (voice,
@@ -545,14 +547,18 @@ call_added_cb (MMModemVoice *voice,
static void static void
call_deleted_cb (MMModemVoice *voice, call_deleted_cb (MMModemVoice *voice,
const char *path, const char *path,
CallsMMOrigin *self) gpointer user_data)
{ {
g_autoptr (CallsMMOrigin) self = NULL;
gpointer call; gpointer call;
gpointer key; gpointer key;
const char *mm_reason; const char *mm_reason;
g_assert (CALLS_IS_MM_ORIGIN (user_data));
self = CALLS_MM_ORIGIN (user_data);
g_debug ("Removing call `%s'", path); g_debug ("Removing call `%s'", path);
g_hash_table_steal_extended (self->calls, path, &key, &call); g_hash_table_steal_extended (self->calls, path, &key, &call);
@@ -577,13 +583,17 @@ call_deleted_cb (MMModemVoice *voice,
static void static void
list_calls_cb (MMModemVoice *voice, list_calls_cb (MMModemVoice *voice,
GAsyncResult *res, GAsyncResult *res,
CallsMMOrigin *self) gpointer user_data)
{ {
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
g_autoptr (CallsMMOrigin) self = NULL;
GList *calls; GList *calls;
g_assert (CALLS_IS_MM_ORIGIN (user_data));
self = CALLS_MM_ORIGIN (user_data);
calls = mm_modem_voice_list_calls_finish (voice, res, &error); calls = mm_modem_voice_list_calls_finish (voice, res, &error);
if (!calls) { if (!calls) {
if (error) { if (error) {
@@ -760,9 +770,12 @@ get_sim_ready_cb (MMModem *modem,
GAsyncResult *res, GAsyncResult *res,
gpointer user_data) gpointer user_data)
{ {
CallsMMOrigin *self = CALLS_MM_ORIGIN (user_data); g_autoptr (CallsMMOrigin) self = NULL;
const char *code; const char *code;
g_assert (CALLS_IS_MM_ORIGIN (user_data));
self = CALLS_MM_ORIGIN (user_data);
self->sim = mm_modem_get_sim_finish (modem, res, NULL); self->sim = mm_modem_get_sim_finish (modem, res, NULL);
code = get_country_iso_for_mcc (mm_sim_get_imsi (self->sim)); code = get_country_iso_for_mcc (mm_sim_get_imsi (self->sim));
@@ -792,7 +805,7 @@ constructed (GObject *object)
mm_modem_get_sim (modem, mm_modem_get_sim (modem,
NULL, NULL,
(GAsyncReadyCallback) get_sim_ready_cb, (GAsyncReadyCallback) get_sim_ready_cb,
self); g_object_ref (self));
g_signal_connect_object (self->mm_obj, "notify::modem3gpp-ussd", g_signal_connect_object (self->mm_obj, "notify::modem3gpp-ussd",
G_CALLBACK (call_mm_ussd_changed_cb), self, G_CALLBACK (call_mm_ussd_changed_cb), self,
@@ -810,7 +823,7 @@ constructed (GObject *object)
mm_modem_voice_list_calls (self->voice, mm_modem_voice_list_calls (self->voice,
NULL, NULL,
(GAsyncReadyCallback) list_calls_cb, (GAsyncReadyCallback) list_calls_cb,
self); g_object_ref (self));
} }