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.
This commit is contained in:
@@ -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 (!tempVolume.IsPersistent())
|
||||
continue;
|
||||
|
||||
if (strcmp(name, "system") == 0
|
||||
|| strcmp(name, "config") == 0) {
|
||||
// Don't include virtual volumes.
|
||||
continue;
|
||||
}
|
||||
AddTab(new VolumeView(name, volume), item);
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user