chiark / gitweb /
libudev: device - allocate envp array only once
[elogind.git] / udev / lib / libudev-device.c
index b8f4b8ba7127fc51868055fddba43bfb09f0ef8e..11a6037d1b823006fd117568ff50037a846cd530 100644 (file)
@@ -1025,8 +1025,8 @@ static int update_envp_monitor_buf(struct udev_device *udev_device)
                return -ENOMEM;
 
        /* envp array, strings will point into monitor buffer */
-       free(udev_device->envp);
-       udev_device->envp = malloc(sizeof(char *) * ENVP_SIZE);
+       if (udev_device->envp == NULL)
+               udev_device->envp = malloc(sizeof(char *) * ENVP_SIZE);
        if (udev_device->envp == NULL)
                return -ENOMEM;
 
@@ -1079,7 +1079,7 @@ static int update_envp_monitor_buf(struct udev_device *udev_device)
 char **udev_device_get_properties_envp(struct udev_device *udev_device)
 {
        if (!udev_device->envp_uptodate)
-               if (update_envp_monitor_buf(udev_device) < 32)
+               if (update_envp_monitor_buf(udev_device) != 0)
                        return NULL;
        return udev_device->envp;
 }
@@ -1087,7 +1087,7 @@ char **udev_device_get_properties_envp(struct udev_device *udev_device)
 ssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device, const char **buf)
 {
        if (!udev_device->envp_uptodate)
-               if (update_envp_monitor_buf(udev_device) < 32)
+               if (update_envp_monitor_buf(udev_device) != 0)
                        return -EINVAL;
        *buf = udev_device->monitor_buf;
        return udev_device->monitor_buf_len;