From 8899e006aab3e0831214d187596eef450b5e21b7 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 3 Feb 2016 18:28:46 +0100 Subject: Fix memleaks related to get_dirname get_dirname may return NULL instead of the original string, so avoid patterns like get_dirname(strdup(x)). Writing to cf_path.toUtf8().data() is fine btw, toUtf8() returns new memory. This fixes two memleak reported by LeakSanitizer via fileset_add_dir and MainWindow::captureFileReadFinished (both via cf_callback_invoke). Change-Id: I0f1528763e77e1f55b54b6674c890a9d02302ee8 Reviewed-on: https://code.wireshark.org/review/13691 Petri-Dish: Dario Lombardo Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- ui/qt/main_window.cpp | 8 ++++---- ui/qt/main_window_slots.cpp | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'ui/qt') diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 2dbcd25074..8f43775486 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -1323,8 +1323,8 @@ void MainWindow::saveAsCaptureFile(capture_file *cf, bool must_support_comments, case CF_WRITE_OK: /* The save succeeded; we're done. */ /* Save the directory name for future file dialogs. */ - dirname = get_dirname(qstring_strdup(file_name)); /* Overwrites cf_name */ - set_last_open_dir(dirname); + dirname = qstring_strdup(file_name); /* Overwrites cf_name */ + set_last_open_dir(get_dirname(dirname)); g_free(dirname); /* If we discarded comments, redraw the packet list to reflect any packets that no longer have comments. */ @@ -1463,8 +1463,8 @@ void MainWindow::exportSelectedPackets() { case CF_WRITE_OK: /* The save succeeded; we're done. */ /* Save the directory name for future file dialogs. */ - dirname = get_dirname(qstring_strdup(file_name)); /* Overwrites cf_name */ - set_last_open_dir(dirname); + dirname = qstring_strdup(file_name); /* Overwrites cf_name */ + set_last_open_dir(get_dirname(dirname)); g_free(dirname); /* If we discarded comments, redraw the packet list to reflect any packets that no longer have comments. */ diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 1881350e41..a12649910f 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -261,7 +261,7 @@ bool MainWindow::openCaptureFile(QString cf_path, QString read_filter, unsigned } break; } - // get_dirname overwrites its path. Hopefully this isn't a problem. + // get_dirname overwrites its path. wsApp->setLastOpenDir(get_dirname(cf_path.toUtf8().data())); main_ui_->statusBar->showExpert(); @@ -706,8 +706,8 @@ void MainWindow::captureFileReadFinished() { add_menu_recent_capture_file(capture_file_.capFile()->filename); /* Remember folder for next Open dialog and save it in recent */ - dir_path = get_dirname(g_strdup(capture_file_.capFile()->filename)); - wsApp->setLastOpenDir(dir_path); + dir_path = g_strdup(capture_file_.capFile()->filename); + wsApp->setLastOpenDir(get_dirname(dir_path)); g_free(dir_path); } -- cgit v1.2.3