Re: [PATCH] Correct two memory leaks triggered by udev events

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/24/2010 12:10 PM, Nigel Jones wrote:
>>From 6c8183e83fbfeb031b16cf9ae2d41b16e3145378 Mon Sep 17 00:00:00 2001
> From: Nigel Jones <dev@xxxxxxxxxx>
> Date: Mon, 24 May 2010 15:05:53 +0000
> Subject: [PATCH] Patch 2 memory leaks.
> 
> 1. Ensure that memory is free'd from udevAddOneDevice() if the return
>    value will be non-zero
> 2. Release udev device reference in udevEventHandleCallback()
>    similar to the release of the reference in udevProcessDeviceListEntry()
> ---
>  src/node_device/node_device_udev.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/src/node_device/node_device_udev.c
> b/src/node_device/node_device_udev.c
> index a1ced87..4d0effa 100644
> --- a/src/node_device/node_device_udev.c
> +++ b/src/node_device/node_device_udev.c
> @@ -1296,6 +1296,9 @@ static int udevAddOneDevice(struct udev_device *device)
>      ret = 0;
> 
>  out:
> +    if (ret != 0) {
> +       virNodeDeviceDefFree(def); /* Free assigned memory to prevent leaks */
> +    }
>      return ret;
>  }
> 
> @@ -1426,6 +1429,7 @@ static void udevEventHandleCallback(int watch
> ATTRIBUTE_UNUSED,
>      }
> 
>  out:
> +    udev_device_unref(device);
>      return;
>  }
> 

Good catch on both of these.  I had to convince myself that udev_device_unref()
would handle a NULL device (in the case of error before we allocated device), but it does.

ACK

-- 
Chris Lalancette

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]