Fix memory leak in write_prefs
authorMikael Kanstrup <mikael.kanstrup@gmail.com>
Mon, 23 Nov 2015 15:33:42 +0000 (16:33 +0100)
committerPeter Wu <peter@lekensteyn.nl>
Wed, 25 Nov 2015 14:18:47 +0000 (14:18 +0000)
Valgrind reports leaks like these:
384 bytes in 8 blocks are definitely lost in loss record 43,909 of 46,703
  at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  by 0xD6A055F: __vasprintf_chk (vasprintf_chk.c:80)
  by 0xA5FD0FB: g_vasprintf (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
  by 0xA5D8C7F: g_strdup_vprintf (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
  by 0xA5D8D1B: g_strdup_printf (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
  by 0x6854FA6: write_prefs (prefs.c:4941)
  by 0x733A9A: prefs_main_write (preference_utils.c:266)
  by 0x5F8A5C: CaptureInterfacesDialog::saveOptionsToPreferences() (capture_interfaces_dialog.cpp:851)
  by 0x5F93CD: CaptureInterfacesDialog::on_manage_clicked() (capture_interfaces_dialog.cpp:858)
  by 0x7182AC: CaptureInterfacesDialog::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (capture_interfaces_dialog.moc.cpp:316)
  by 0x718822: CaptureInterfacesDialog::qt_metacall(QMetaObject::Call, int, void**) (capture_interfaces_dialog.moc.cpp:413)
  by 0xBEBE36C: QMetaObject::activate(QObject*, int, int, void**) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)

When storing user preferences the constructed pathname of user's
preferences file is not freed properly.

Change-Id: I5cdc53ca836503af048e1d06e4614d83ef8921ac
Reviewed-on: https://code.wireshark.org/review/12114
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
epan/prefs.c

index a1b4072b0e0a882351b0c1fa50dc3a81f6c39e1f..4dd4e54244e7c9b242e1d8469571d08b56f2a96c 100644 (file)
@@ -4944,6 +4944,7 @@ write_prefs(char **pf_path_return)
             *pf_path_return = pf_path;
             return errno;
         }
+        g_free(pf_path);
     } else {
         pf = stdout;
     }