From 04adb291a6f5e4fd042fdd5ad1f53f9f9d936441 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 7 Oct 2007 14:56:26 +0000 Subject: [PATCH] Clear the user_partition_data::user_data fields before updating the BPartition structure with the data retrieved from the kernel. For new partitions the field is not set in the next step and later code would use an initialized pointer. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22471 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/storage/DiskDevice.h | 2 ++ src/kits/storage/DiskDevice.cpp | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/headers/private/storage/DiskDevice.h b/headers/private/storage/DiskDevice.h index e11f06caf6..5879c30928 100644 --- a/headers/private/storage/DiskDevice.h +++ b/headers/private/storage/DiskDevice.h @@ -52,6 +52,8 @@ private: status_t _Update(bool shadow, bool *updated); status_t _Update(user_disk_device_data *data, bool *updated); + static void _ClearUserData(user_partition_data* data); + virtual bool _AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level); user_disk_device_data *fDeviceData; diff --git a/src/kits/storage/DiskDevice.cpp b/src/kits/storage/DiskDevice.cpp index c084db4218..f8cab70688 100644 --- a/src/kits/storage/DiskDevice.cpp +++ b/src/kits/storage/DiskDevice.cpp @@ -377,11 +377,16 @@ BDiskDevice::_Update(user_disk_device_data *data, bool *updated) if (!updated) updated = &_updated; *updated = false; + + // clear the user_data fields first + _ClearUserData(&data->device_partition_data); + // remove obsolete partitions status_t error = _RemoveObsoleteDescendants(&data->device_partition_data, - updated); + updated); if (error != B_OK) return error; + // update existing partitions and add new ones error = BPartition::_Update(&data->device_partition_data, updated); if (error == B_OK) { @@ -404,3 +409,14 @@ BDiskDevice::_AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level) return visitor->Visit(this); } + +// _ClearUserData +void +BDiskDevice::_ClearUserData(user_partition_data* data) +{ + data->user_data = NULL; + + // recurse + for (int i = 0; i < data->child_count; i++) + _ClearUserData(data->children[i]); +}