[PATCH] tests: fix memory leaks
Aleksander Morgado
aleksander at aleksander.es
Fri May 30 04:32:02 PDT 2014
On 30/05/14 08:19, Ben Chan wrote:
> This patch fixes memory leaks in unit tests detected by LeakSanitizer.
> ---
> src/tests/test-modem-helpers.c | 10 ++++++++++
> src/tests/test-qcdm-serial-port.c | 1 +
> src/tests/test-sms-part-3gpp.c | 7 ++++++-
> 3 files changed, 17 insertions(+), 1 deletion(-)
>
Pushed, thanks.
> diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c
> index af28656..cc96261 100644
> --- a/src/tests/test-modem-helpers.c
> +++ b/src/tests/test-modem-helpers.c
> @@ -711,6 +711,7 @@ test_creg_match (const char *test,
> g_assert_cmpuint (regex_num, ==, result->regex_num);
>
> success = mm_3gpp_parse_creg_response (info, &state, &lac, &ci, &access_tech, &cgreg, &cereg, &error);
> + g_match_info_free (info);
> g_assert (success);
> g_assert_no_error (error);
> g_assert_cmpuint (state, ==, result->state);
> @@ -1445,6 +1446,7 @@ test_devid_item (void *f, gpointer d)
> if (strcmp (devid, item->devid))
> g_message ("%s", devid);
> g_assert (!strcmp (devid, item->devid));
> + g_free (devid);
> }
>
> /*****************************************************************************/
> @@ -1536,6 +1538,7 @@ test_iccid_parse_quoted_swap_19_digit (void *f, gpointer d)
> parsed = mm_3gpp_parse_iccid (raw_iccid, &error);
> g_assert_no_error (error);
> g_assert_cmpstr (parsed, ==, expected);
> + g_free (parsed);
> }
>
> static void
> @@ -1549,6 +1552,7 @@ test_iccid_parse_unquoted_swap_20_digit (void *f, gpointer d)
> parsed = mm_3gpp_parse_iccid (raw_iccid, &error);
> g_assert_no_error (error);
> g_assert_cmpstr (parsed, ==, expected);
> + g_free (parsed);
> }
>
> static void
> @@ -1562,6 +1566,7 @@ test_iccid_parse_unquoted_unswapped_19_digit (void *f, gpointer d)
> parsed = mm_3gpp_parse_iccid (raw_iccid, &error);
> g_assert_no_error (error);
> g_assert_cmpstr (parsed, ==, expected);
> + g_free (parsed);
> }
>
> static void
> @@ -1575,6 +1580,7 @@ test_iccid_parse_quoted_unswapped_20_digit (void *f, gpointer d)
> parsed = mm_3gpp_parse_iccid (raw_iccid, &error);
> g_assert_no_error (error);
> g_assert_cmpstr (parsed, ==, expected);
> + g_free (parsed);
> }
>
> static void
> @@ -1586,6 +1592,7 @@ test_iccid_parse_short (void *f, gpointer d)
>
> parsed = mm_3gpp_parse_iccid (raw_iccid, &error);
> g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED);
> + g_free (parsed);
> }
>
> static void
> @@ -1597,6 +1604,7 @@ test_iccid_parse_invalid_chars (void *f, gpointer d)
>
> parsed = mm_3gpp_parse_iccid (raw_iccid, &error);
> g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED);
> + g_free (parsed);
> }
>
> static void
> @@ -1608,6 +1616,7 @@ test_iccid_parse_quoted_invalid_mii (void *f, gpointer d)
>
> parsed = mm_3gpp_parse_iccid (raw_iccid, &error);
> g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED);
> + g_free (parsed);
> }
>
> static void
> @@ -1619,6 +1628,7 @@ test_iccid_parse_unquoted_invalid_mii (void *f, gpointer d)
>
> parsed = mm_3gpp_parse_iccid (raw_iccid, &error);
> g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED);
> + g_free (parsed);
> }
>
> /*****************************************************************************/
> diff --git a/src/tests/test-qcdm-serial-port.c b/src/tests/test-qcdm-serial-port.c
> index e7bc2f1..cd9365b 100644
> --- a/src/tests/test-qcdm-serial-port.c
> +++ b/src/tests/test-qcdm-serial-port.c
> @@ -227,6 +227,7 @@ qcdm_test_child (int fd, GAsyncReadyCallback cb)
>
> qcdm_request_verinfo (port, cb, loop);
> g_main_loop_run (loop);
> + g_main_loop_unref (loop);
>
> mm_port_serial_close (MM_PORT_SERIAL (port));
> g_object_unref (port);
> diff --git a/src/tests/test-sms-part-3gpp.c b/src/tests/test-sms-part-3gpp.c
> index 58de8a6..dc470d7 100644
> --- a/src/tests/test-sms-part-3gpp.c
> +++ b/src/tests/test-sms-part-3gpp.c
> @@ -528,10 +528,12 @@ common_test_create_pdu (const gchar *smsc,
> if (number)
> mm_sms_part_set_number (part, number);
> if (text) {
> + gchar **out;
> MMSmsEncoding encoding = MM_SMS_ENCODING_UNKNOWN;
>
> /* Detect best encoding */
> - mm_sms_part_3gpp_util_split_text (text, &encoding);
> + out = mm_sms_part_3gpp_util_split_text (text, &encoding);
> + g_strfreev (out);
> mm_sms_part_set_text (part, text);
> mm_sms_part_set_encoding (part, encoding);
> }
> @@ -544,6 +546,7 @@ common_test_create_pdu (const gchar *smsc,
> &len,
> &msgstart,
> &error);
> + mm_sms_part_free (part);
>
> trace_pdu (pdu, len);
>
> @@ -726,6 +729,8 @@ common_test_text_split (const gchar *text,
> for (i = 0; out[i]; i++) {
> g_assert_cmpstr (out[i], ==, expected[i]);
> }
> +
> + g_strfreev (out);
> }
>
> static void
>
--
Aleksander
https://aleksander.es
More information about the ModemManager-devel
mailing list