discover/udev: dup property values returned from udev
authorJeremy Kerr <jk@ozlabs.org>
Wed, 9 Oct 2013 08:38:56 +0000 (16:38 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 9 Oct 2013 09:22:46 +0000 (17:22 +0800)
The property strings are managed by the udev code, so we need to strdup.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/udev.c

index e996e221228804d6a16a7a41aeb25463198800a8..6212e4309137f47feb97cd0b09043193fdc13191 100644 (file)
@@ -73,6 +73,7 @@ static int udev_handle_dev_add(struct pb_udev *udev, struct udev_device *dev)
        const char *serial;
        const char *path;
        const char *name;
+       const char *prop;
 
        name = udev_device_get_sysname(dev);
        if (!name) {
@@ -114,8 +115,12 @@ static int udev_handle_dev_add(struct pb_udev *udev, struct udev_device *dev)
        ddev = discover_device_create(udev->handler, name);
 
        ddev->device_path = udev_device_get_devnode(dev);
-       ddev->uuid = udev_device_get_property_value(dev, "ID_FS_UUID");
-       ddev->label = udev_device_get_property_value(dev, "ID_FS_LABEL");
+       prop = udev_device_get_property_value(dev, "ID_FS_UUID");
+       if (prop)
+               ddev->uuid = talloc_strdup(ddev, prop);
+       prop = udev_device_get_property_value(dev, "ID_FS_LABEL");
+       if (prop)
+               ddev->label = talloc_strdup(ddev, prop);
        ddev->device->type = DEVICE_TYPE_DISK;
 
        udev_setup_device_params(dev, ddev);