OSDN Git Service

_device_unregister: check for unregistering the same device twice
[android-x86/external-parted.git] / libparted / device.c
index f20121b..4c43e09 100644 (file)
@@ -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