core: fix memory leaks
Since MMModem is an interface and doesn't store stuff like the modem's physdev internally (since it's an interface) these things are handled via GObject properties. And since g_object_get() returns allocated values, we need to free the returned value from mm_modem_get_device() after we're done with it.
This commit is contained in:
@@ -207,7 +207,7 @@ static void
|
|||||||
check_export_modem (MMManager *self, MMModem *modem)
|
check_export_modem (MMManager *self, MMModem *modem)
|
||||||
{
|
{
|
||||||
MMManagerPrivate *priv = MM_MANAGER_GET_PRIVATE (self);
|
MMManagerPrivate *priv = MM_MANAGER_GET_PRIVATE (self);
|
||||||
const char *modem_physdev;
|
char *modem_physdev;
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
gpointer value;
|
gpointer value;
|
||||||
|
|
||||||
@@ -235,8 +235,8 @@ check_export_modem (MMManager *self, MMModem *modem)
|
|||||||
|
|
||||||
if (!strcmp (info->physdev_path, modem_physdev)) {
|
if (!strcmp (info->physdev_path, modem_physdev)) {
|
||||||
g_debug ("(%s/%s): outstanding support task prevents export of %s",
|
g_debug ("(%s/%s): outstanding support task prevents export of %s",
|
||||||
info->subsys, info->name, mm_modem_get_device (modem));
|
info->subsys, info->name, modem_physdev);
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,21 +244,18 @@ check_export_modem (MMManager *self, MMModem *modem)
|
|||||||
* discovers another of the modem's ports.
|
* discovers another of the modem's ports.
|
||||||
*/
|
*/
|
||||||
if (g_object_get_data (G_OBJECT (modem), DBUS_PATH_TAG))
|
if (g_object_get_data (G_OBJECT (modem), DBUS_PATH_TAG))
|
||||||
return;
|
goto out;
|
||||||
|
|
||||||
/* No outstanding port tasks, so if the modem is valid we can export it */
|
/* No outstanding port tasks, so if the modem is valid we can export it */
|
||||||
if (mm_modem_get_valid (modem)) {
|
if (mm_modem_get_valid (modem)) {
|
||||||
static guint32 id = 0;
|
static guint32 id = 0;
|
||||||
char *path, *device, *data_device = NULL;
|
char *path, *data_device = NULL;
|
||||||
|
|
||||||
path = g_strdup_printf (MM_DBUS_PATH"/Modems/%d", id++);
|
path = g_strdup_printf (MM_DBUS_PATH"/Modems/%d", id++);
|
||||||
dbus_g_connection_register_g_object (priv->connection, path, G_OBJECT (modem));
|
dbus_g_connection_register_g_object (priv->connection, path, G_OBJECT (modem));
|
||||||
g_object_set_data_full (G_OBJECT (modem), DBUS_PATH_TAG, path, (GDestroyNotify) g_free);
|
g_object_set_data_full (G_OBJECT (modem), DBUS_PATH_TAG, path, (GDestroyNotify) g_free);
|
||||||
|
|
||||||
device = mm_modem_get_device (modem);
|
g_debug ("Exported modem %s as %s", modem_physdev, path);
|
||||||
g_assert (device);
|
|
||||||
g_debug ("Exported modem %s as %s", device, path);
|
|
||||||
g_free (device);
|
|
||||||
|
|
||||||
g_object_get (G_OBJECT (modem), MM_MODEM_DATA_DEVICE, &data_device, NULL);
|
g_object_get (G_OBJECT (modem), MM_MODEM_DATA_DEVICE, &data_device, NULL);
|
||||||
g_debug ("(%s): data port is %s", path, data_device);
|
g_debug ("(%s): data port is %s", path, data_device);
|
||||||
@@ -266,6 +263,9 @@ check_export_modem (MMManager *self, MMModem *modem)
|
|||||||
|
|
||||||
g_signal_emit (self, signals[DEVICE_ADDED], 0, modem);
|
g_signal_emit (self, signals[DEVICE_ADDED], 0, modem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
g_free (modem_physdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -333,15 +333,18 @@ find_modem_for_device (MMManager *manager, const char *device)
|
|||||||
MMManagerPrivate *priv = MM_MANAGER_GET_PRIVATE (manager);
|
MMManagerPrivate *priv = MM_MANAGER_GET_PRIVATE (manager);
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
gpointer key, value;
|
gpointer key, value;
|
||||||
|
MMModem *found = NULL;
|
||||||
|
|
||||||
g_hash_table_iter_init (&iter, priv->modems);
|
g_hash_table_iter_init (&iter, priv->modems);
|
||||||
while (g_hash_table_iter_next (&iter, &key, &value)) {
|
while (g_hash_table_iter_next (&iter, &key, &value) && !found) {
|
||||||
MMModem *modem = MM_MODEM (value);
|
MMModem *candidate = MM_MODEM (value);
|
||||||
|
char *candidate_device = mm_modem_get_device (candidate);
|
||||||
|
|
||||||
if (!strcmp (device, mm_modem_get_device (modem)))
|
if (!strcmp (device, candidate_device))
|
||||||
return modem;
|
found = candidate;
|
||||||
|
g_free (candidate_device);
|
||||||
}
|
}
|
||||||
return NULL;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -521,6 +524,7 @@ do_grab_port (gpointer user_data)
|
|||||||
if (modem) {
|
if (modem) {
|
||||||
guint32 modem_type = MM_MODEM_TYPE_UNKNOWN;
|
guint32 modem_type = MM_MODEM_TYPE_UNKNOWN;
|
||||||
const char *type_name = "UNKNOWN";
|
const char *type_name = "UNKNOWN";
|
||||||
|
char *device;;
|
||||||
|
|
||||||
g_object_get (G_OBJECT (modem), MM_MODEM_TYPE, &modem_type, NULL);
|
g_object_get (G_OBJECT (modem), MM_MODEM_TYPE, &modem_type, NULL);
|
||||||
if (modem_type == MM_MODEM_TYPE_GSM)
|
if (modem_type == MM_MODEM_TYPE_GSM)
|
||||||
@@ -528,11 +532,13 @@ do_grab_port (gpointer user_data)
|
|||||||
else if (modem_type == MM_MODEM_TYPE_CDMA)
|
else if (modem_type == MM_MODEM_TYPE_CDMA)
|
||||||
type_name = "CDMA";
|
type_name = "CDMA";
|
||||||
|
|
||||||
|
device = mm_modem_get_device (modem);
|
||||||
g_message ("(%s): %s modem %s claimed port %s",
|
g_message ("(%s): %s modem %s claimed port %s",
|
||||||
mm_plugin_get_name (info->best_plugin),
|
mm_plugin_get_name (info->best_plugin),
|
||||||
type_name,
|
type_name,
|
||||||
mm_modem_get_device (modem),
|
device,
|
||||||
info->name);
|
info->name);
|
||||||
|
g_free (device);
|
||||||
|
|
||||||
add_modem (info->manager, modem, info->best_plugin);
|
add_modem (info->manager, modem, info->best_plugin);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -102,7 +102,7 @@ mm_modem_base_add_port (MMModemBase *self,
|
|||||||
{
|
{
|
||||||
MMModemBasePrivate *priv = MM_MODEM_BASE_GET_PRIVATE (self);
|
MMModemBasePrivate *priv = MM_MODEM_BASE_GET_PRIVATE (self);
|
||||||
MMPort *port = NULL;
|
MMPort *port = NULL;
|
||||||
char *key;
|
char *key, *device;
|
||||||
|
|
||||||
g_return_val_if_fail (MM_IS_MODEM_BASE (self), NULL);
|
g_return_val_if_fail (MM_IS_MODEM_BASE (self), NULL);
|
||||||
g_return_val_if_fail (subsys != NULL, NULL);
|
g_return_val_if_fail (subsys != NULL, NULL);
|
||||||
@@ -138,10 +138,13 @@ mm_modem_base_add_port (MMModemBase *self,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (mm_options_debug ()) {
|
if (mm_options_debug ()) {
|
||||||
|
device = mm_modem_get_device (MM_MODEM (self));
|
||||||
|
|
||||||
g_message ("(%s) type %s claimed by %s",
|
g_message ("(%s) type %s claimed by %s",
|
||||||
name,
|
name,
|
||||||
mm_port_type_to_name (ptype),
|
mm_port_type_to_name (ptype),
|
||||||
mm_modem_get_device (MM_MODEM (self)));
|
device);
|
||||||
|
g_free (device);
|
||||||
}
|
}
|
||||||
key = get_hash_key (subsys, name);
|
key = get_hash_key (subsys, name);
|
||||||
g_hash_table_insert (priv->ports, key, port);
|
g_hash_table_insert (priv->ports, key, port);
|
||||||
|
@@ -150,12 +150,15 @@ disable_disconnect_done (MMModem *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
char *device = mm_modem_get_device (self);
|
||||||
|
|
||||||
/* Don't really care what the error was; log it and proceed to disable */
|
/* Don't really care what the error was; log it and proceed to disable */
|
||||||
g_warning ("%s: (%s): error disconnecting the modem while disabling: (%d) %s",
|
g_warning ("%s: (%s): error disconnecting the modem while disabling: (%d) %s",
|
||||||
__func__,
|
__func__,
|
||||||
mm_modem_get_device (self),
|
device,
|
||||||
error ? error->code : -1,
|
error ? error->code : -1,
|
||||||
error && error->message ? error->message : "(unknown)");
|
error && error->message ? error->message : "(unknown)");
|
||||||
|
g_free (device);
|
||||||
}
|
}
|
||||||
finish_disable (self, cb_data->callback, cb_data->user_data);
|
finish_disable (self, cb_data->callback, cb_data->user_data);
|
||||||
g_free (cb_data);
|
g_free (cb_data);
|
||||||
|
Reference in New Issue
Block a user