From 4af29e02aab03cb80df7db5b09cc2eddab2249e2 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 28 Apr 2010 19:14:36 +0200 Subject: [PATCH] _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 . --- NEWS | 3 +++ libparted/device.c | 10 ++++++++++ 2 files changed, 13 insertions(+) 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 -- 2.11.0