[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH parted 2/2] _device_unregister: check for unregistering the same
From: |
Hans de Goede |
Subject: |
[PATCH parted 2/2] _device_unregister: check for unregistering the same device twice |
Date: |
Wed, 28 Apr 2010 19:14:36 +0200 |
_device_unregister() can get called 2 times for the same device if
a libparted user explictly removes the device from the cache using
ped_device_cache_remove(), it gets called and it then becomes the
user's responsibility to free the PedDevice by calling
ped_device_destroy(). ped_device_destroy() will then call
_device_unregister() a second time with the same device, so if the
device is not found in the list do nothing.
* libparted/device.c(_device_unregister): check for unregistering
the same device twice.
---
NEWS | 3 +++
libparted/device.c | 10 ++++++++++
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/NEWS b/NEWS
index ddbc893..77d893a 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,9 @@ GNU parted NEWS -*-
outline -*-
libparted now properly checks the return value of dm_task_run when
operating on devicemapper devices.
+ allow using ped_device_cache_remove(dev) followed by a (later)
+ ped_device_destroy() without corrupting the device cache.
+
** Changes in behavior
libparted no longer issues an exception/warning about >512-byte
diff --git a/libparted/device.c b/libparted/device.c
index f20121b..00f49a3 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -73,6 +73,16 @@ _device_unregister (PedDevice* dev)
if (walk == dev) break;
}
+ /* We can get called 2 times for the same device if a libparted user
+ explictly removes the device from the cache using
+ ped_device_cache_remove(), we get called and it then becomes the
+ user's responsibility to free the PedDevice by calling
+ ped_device_destroy().
+ ped_device_destroy() will then call us a second time, so if the
+ device is not found in the list do nothing. */
+ if (walk == NULL)
+ return;
+
if (last)
last->next = dev->next;
else
--
1.7.0.1