hrev48897 adds 1 changeset to branch 'master' old head: 24bb6e132db1ff97c26abf00f2b8df9155f48039 new head: 93e5d9fa15488a96d30252b17d279c286b915209 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=93e5d9fa1548+%5E24bb6e132db1 ---------------------------------------------------------------------------- 93e5d9fa1548: DiskUsage: Fix CID 1288122 In hrev48870 I made some updates to DiskUsage which accidentally caused this CID. Both the volume and item pointers were going out of scope without being deleted in the error case leading to a resource leak. This commit seeks to fix the problem by creating these objects as late as possible after the error checking. tempVolume, which, as it's name implies, is created temporarily on the stack is used instead of volume up until the point that AddTab() requires a more permanent heap-stored volume pointer. Same goes for the VolumeView and VolumeTab. name is created temporarily on the stack as well which works because it is copied when passed into VolumeView constructor by the grandparent BHandler before going out of scope. [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev48897 Commit: 93e5d9fa15488a96d30252b17d279c286b915209 URL: http://cgit.haiku-os.org/haiku/commit/?id=93e5d9fa1548 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Mar 13 20:14:35 2015 UTC ---------------------------------------------------------------------------- 1 file changed, 16 insertions(+), 13 deletions(-) src/apps/diskusage/ControlsView.cpp | 29 ++++++++++++++++------------- ---------------------------------------------------------------------------- diff --git a/src/apps/diskusage/ControlsView.cpp b/src/apps/diskusage/ControlsView.cpp index 47840e3..67c1c84 100644 --- a/src/apps/diskusage/ControlsView.cpp +++ b/src/apps/diskusage/ControlsView.cpp @@ -224,20 +224,23 @@ ControlsView::VolumeTabView::AttachedToWindow() BVolume tempVolume; while (fVolumeRoster->GetNextVolume(&tempVolume) == B_OK) { - if (tempVolume.IsPersistent()) { - BVolume* volume = new BVolume(tempVolume); - VolumeTab* item = new VolumeTab(volume); - char name[B_PATH_NAME_LENGTH]; - if (volume->GetName(name) != B_OK) - continue; - - if (strcmp(name, "system") == 0 - || strcmp(name, "config") == 0) { - // Don't include virtual volumes. - continue; - } - AddTab(new VolumeView(name, volume), item); + if (!tempVolume.IsPersistent()) + continue; + + char name[B_PATH_NAME_LENGTH]; + if (tempVolume.GetName(name) != B_OK) + continue; + + if (strcmp(name, "system") == 0 + || strcmp(name, "config") == 0) { + // Don't include virtual volumes. + continue; } + + BVolume* volume = new BVolume(tempVolume); + VolumeView* volumeView = new VolumeView(name, volume); + VolumeTab* volumeTab = new VolumeTab(volume); + AddTab(volumeView, volumeTab); } // Begin watching mount and unmount events.