libmm-glib: deep-copy ports array in ensure_internal_ports() (bgo #724900)
ensure_internal_ports() didn't deep-copy the ports array, which meant that anything calling mm_modem_port_info_array_free() was freeing the internal memory owned by MMModem if it retrieved the array with mm_modem_get_ports(). https://bugzilla.gnome.org/show_bug.cgi?id=724900
This commit is contained in:
@@ -752,6 +752,7 @@ ensure_internal_ports (MMModem *self,
|
||||
guint *dup_ports_n)
|
||||
{
|
||||
gboolean ret;
|
||||
guint i;
|
||||
|
||||
g_mutex_lock (&self->priv->ports_mutex);
|
||||
{
|
||||
@@ -783,7 +784,15 @@ ensure_internal_ports (MMModem *self,
|
||||
*dup_ports_n = self->priv->ports->len;
|
||||
if (self->priv->ports->len > 0) {
|
||||
*dup_ports = g_malloc (sizeof (MMModemPortInfo) * self->priv->ports->len);
|
||||
memcpy (*dup_ports, self->priv->ports->data, sizeof (MMModemPortInfo) * self->priv->ports->len);
|
||||
|
||||
/* Deep-copy the array */
|
||||
for (i = 0; i < self->priv->ports->len; i++) {
|
||||
MMModemPortInfo *dst = &(*dup_ports)[i];
|
||||
MMModemPortInfo *src = &g_array_index (self->priv->ports, MMModemPortInfo, i);
|
||||
|
||||
dst->name = g_strdup (src->name);
|
||||
dst->type = src->type;
|
||||
}
|
||||
} else
|
||||
*dup_ports = NULL;
|
||||
}
|
||||
@@ -795,7 +804,7 @@ ensure_internal_ports (MMModem *self,
|
||||
}
|
||||
|
||||
/**
|
||||
* mm_modem_peek_current_ports:
|
||||
* mm_modem_peek_ports:
|
||||
* @self: A #MMModem.
|
||||
* @ports: (out) (array length=n_ports) (transfer none): Return location for the array of #MMModemPortInfo values. Do not free the returned value, it is owned by @self.
|
||||
* @n_ports: (out): Return location for the number of values in @ports.
|
||||
|
Reference in New Issue
Block a user