[Parted-commits] GNU Parted Official Repository: Changes to 'master'

Jim Meyering meyering at alioth.debian.org
Fri Apr 30 15:44:43 UTC 2010


 NEWS               |    3 +++
 libparted/device.c |   10 ++++++++++
 2 files changed, 13 insertions(+)

New commits:
commit 4af29e02aab03cb80df7db5b09cc2eddab2249e2
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Wed Apr 28 19:14:36 2010 +0200

    _device_unregister: check for unregistering the same device twice
    
    _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.
    Reported by Jan Stodola in <http://bugzilla.redhat.com/568346>.

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..4c43e09 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -73,6 +73,16 @@ _device_unregister (PedDevice* dev)
 		if (walk == dev) break;
 	}
 
+	/* This function may be called twice 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



More information about the Parted-commits mailing list