<div dir="ltr"><div><div><div>Hi Aleksander,<br></div> I tested your patch and the reported issue doesn't appear any longer.<br></div> It all looks good and certainly better (more glib-style) than my initial implementation. Although I wonder if this doesn't ever collide with mm_modem_port_info_array_free() in mm-helper-types.c? It seems that two ways of dealing with memory management are taken for the same data structure, though I didn't observe any double-free's on this part during runtime, so I guess this must be correct.<br></div><div><br>Thanks for looking at this,<br></div><div>Piotr.<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-02-08 18:45 GMT+01:00 Aleksander Morgado <span dir="ltr"><<a href="mailto:aleksander@aleksander.es" target="_blank">aleksander@aleksander.es</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So that we don't leak the port names allocated within each<br>
MMModemPortInfo.<br>
<br>
    ==261== 672 bytes in 84 blocks are definitely lost in loss record 7,314 of 7,383<br>
    ==261== at 0x402C51E: malloc (vg_replace_malloc.c:299)<br>
    ==261== by 0x4484878: g_malloc (gmem.c:94)<br>
    ==261== by 0x449D51D: g_strdup (gstrfuncs.c:363)<br>
    ==261== by 0x44B5B73: g_variant_dup_string (gvariant.c:1529)<br>
    ==261== by 0x44B945E: g_variant_valist_get_nnp (gvariant.c:4775)<br>
    ==261== by 0x44B945E: g_variant_valist_get_leaf (gvariant.c:4945)<br>
    ==261== by 0x44B945E: g_variant_valist_get (gvariant.c:5126)<br>
    ==261== by 0x44B922C: g_variant_valist_get (gvariant.c:5161)<br>
    ==261== by 0x44B9FC9: g_variant_get_va (gvariant.c:5388)<br>
    ==261== by 0x44BA3C5: g_variant_get_child (gvariant.c:5486)<br>
    ==261== by 0x6613FA8: mm_common_ports_variant_to_<wbr>garray (mm-common-helpers.c:238)<br>
    ==261== by 0x6601AB9: ensure_internal_ports (mm-modem.c:766)<br>
    ==261== by 0x6603E42: mm_modem_peek_ports (mm-modem.c:825)<br>
    ==261== by 0x65CD94D: owns_port (nm-modem-broadband.c:196)<br>
<br>
Reported-by: Piotr Figiel <<a href="mailto:p.figiel@camlintechnologies.com">p.figiel@camlintechnologies.<wbr>com</a>><br>
---<br>
<br>
Piotr,<br>
<br>
Could you test this patch instead of the one you provided? In this way we make sure that every g_array_unref() call does the proper disposal of the inner strings, not just during finalize().<br>
<br>
---<br>
 libmm-glib/mm-common-helpers.c | 7 +++++++<br>
 1 file changed, 7 insertions(+)<br>
<br>
diff --git a/libmm-glib/mm-common-<wbr>helpers.c b/libmm-glib/mm-common-<wbr>helpers.c<br>
index 7bd845b9..f99e58d8 100644<br>
--- a/libmm-glib/mm-common-<wbr>helpers.c<br>
+++ b/libmm-glib/mm-common-<wbr>helpers.c<br>
@@ -219,6 +219,12 @@ mm_common_sms_storages_garray_<wbr>to_variant (GArray *array)<br>
     return mm_common_sms_storages_array_<wbr>to_variant (NULL, 0);<br>
 }<br>
<br>
+static void<br>
+clear_modem_port_info (MMModemPortInfo *info)<br>
+{<br>
+    g_free (info->name);<br>
+}<br>
+<br>
 GArray *<br>
 mm_common_ports_variant_to_<wbr>garray (GVariant *variant)<br>
 {<br>
@@ -232,6 +238,7 @@ mm_common_ports_variant_to_<wbr>garray (GVariant *variant)<br>
<br>
         if (n > 0) {<br>
             array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemPortInfo), n);<br>
+            g_array_set_clear_func (array, (GDestroyNotify) clear_modem_port_info);<br>
             for (i = 0; i < n; i++) {<br>
                 MMModemPortInfo info;<br>
<br>
--<br>
2.11.1<br>
</blockquote></div><br></div>