ndef: Fix memory leak in build_ho_record
authorSzymon Janc <szymon.janc@tieto.com>
Fri, 4 Jan 2013 15:10:31 +0000 (16:10 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 31 Jan 2013 00:35:38 +0000 (01:35 +0100)
record data needs to be freed before returning ndef.

144 (80 direct, 64 indirect) bytes in 1 blocks are definitely lost in loss record 142 of 190
   at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FBFD: g_try_malloc0 (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x424477: __ndef_build_from_message (ndef.c:2950)
   by 0x41CEE3: push_ndef (device.c:276)
   by 0x40B850: process_message.isra.4 (object.c:285)
   by 0x5143C40: ??? (in /lib/x86_64-linux-gnu/libdbus-1.so.3.5.8)
   by 0x5135B0F: dbus_connection_dispatch (in /lib/x86_64-linux-gnu/libdbus-1.so.3.5.8)
   by 0x409247: message_dispatch (mainloop.c:76)
   by 0x4E7A91A: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E79D52: g_main_context_dispatch (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E7A09F: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
   by 0x4E7A499: g_main_loop_run (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)

src/ndef.c

index ed8501c..7c68ae4 100644 (file)
@@ -2998,6 +2998,7 @@ static struct near_ndef_message *build_ho_record(DBusMessage *msg)
        char *carrier_type = NULL;
        uint8_t carrier;
        struct near_ndef_record *record = NULL;
+       struct near_ndef_message *ho = NULL;
 
        DBG("");
 
@@ -3043,13 +3044,13 @@ static struct near_ndef_message *build_ho_record(DBusMessage *msg)
                goto fail;
        record->ho->ac_payloads[0] = build_ho_local_ac_record();
 
-       return near_ndef_prepare_handover_record("Hr", record, carrier, NULL);
+       ho = near_ndef_prepare_handover_record("Hr", record, carrier, NULL);
 
 fail:
        free_ho_payload(record->ho);
        g_free(record);
 
-       return NULL;
+       return ho;
 }
 
 struct near_ndef_message *__ndef_build_from_message(DBusMessage *msg)