From: Benjamin Larsson Date: Tue, 12 Apr 2016 18:25:01 +0000 (+0200) Subject: memory leak fix: g_variant_print() usage fix X-Git-Tag: libsigrok-0.5.0~497 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=2c4600191b8442a64717f048c6a77ef77d6169ff;p=libsigrok.git memory leak fix: g_variant_print() usage fix g_variant_print() allocates memory during call. Save the pointer so that it can be free'd afterwards. ==10048== 16 bytes in 1 blocks are definitely lost in loss record 17 of 37 ==10048== at 0x4C2DEAE: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==10048== by 0x536C85D: g_realloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x53877C6: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x5388B60: g_string_append_vprintf (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x5388D83: g_string_append_printf (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x539D034: g_variant_print_string (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x539C92C: g_variant_print (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x4E5F713: log_key (hwdriver.c:597) ==10048== by 0x4E5FCD5: sr_config_set (hwdriver.c:752) ==10048== by 0x408C1A: run_session (session.c:661) ==10048== by 0x404FC5: main (main.c:267) ==10048== ==10048== 16 bytes in 1 blocks are definitely lost in loss record 18 of 37 ==10048== at 0x4C2DEAE: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==10048== by 0x536C85D: g_realloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x53877C6: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x5388B60: g_string_append_vprintf (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x5388D83: g_string_append_printf (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x539D034: g_variant_print_string (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x539C92C: g_variant_print (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4400.1) ==10048== by 0x4E5F713: log_key (hwdriver.c:597) ==10048== by 0x4E5FBDD: sr_config_get (hwdriver.c:709) ==10048== by 0x4080D7: datafeed_in (session.c:196) ==10048== by 0x4E5D47E: sr_session_send (session.c:1192) ==10048== by 0x4E62682: std_session_send_df_header (std.c:101) --- diff --git a/src/hwdriver.c b/src/hwdriver.c index b31242ad..db3f615a 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -586,6 +586,7 @@ static void log_key(const struct sr_dev_inst *sdi, { const char *opstr; const struct sr_key_info *srci; + gchar *tmp_str; /* Don't log SR_CONF_DEVICE_OPTIONS, it's verbose and not too useful. */ if (key == SR_CONF_DEVICE_OPTIONS) @@ -594,9 +595,11 @@ static void log_key(const struct sr_dev_inst *sdi, opstr = op == SR_CONF_GET ? "get" : op == SR_CONF_SET ? "set" : "list"; srci = sr_key_info_get(SR_KEY_CONFIG, key); + tmp_str = g_variant_print(data, TRUE); sr_spew("sr_config_%s(): key %d (%s) sdi %p cg %s -> %s", opstr, key, srci ? srci->id : "NULL", sdi, cg ? cg->name : "NULL", - data ? g_variant_print(data, TRUE) : "NULL"); + data ? tmp_str : "NULL"); + g_free(tmp_str); } static int check_key(const struct sr_dev_driver *driver,