diff options
author | Peter Wu <peter@lekensteyn.nl> | 2016-02-03 18:28:46 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2016-02-04 04:57:30 +0000 |
commit | 8899e006aab3e0831214d187596eef450b5e21b7 (patch) | |
tree | 83b3aebc1c31dcdbd89cb229202b186e6fc57356 /ui/qt/main_window.cpp | |
parent | 36cf75efb15827c801c4e82c8ab3ed16f3e00749 (diff) | |
download | wireshark-8899e006aab3e0831214d187596eef450b5e21b7.tar.gz |
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 <lomato@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt/main_window.cpp')
-rw-r--r-- | ui/qt/main_window.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
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. */ |