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

[libvirt] [PATCH] Correct two memory leaks triggered by udev events



Hi List,

Please find below a patch that should correct two memory leaks within
the udev device handling code.

The issue is triggered by 'add' udev calls and will slowly cause
libvirtd to consume the majority of system memory.

The first part of the patch deals with udevAddOneDevice() and frees
the memory allocated to 'def' if the function would return -1 (an
error condition) due to the inability to look up udev properties (for
example, if the udev device is already removed).

The second part of the patch deals with a remaining 8kB/cycle memory
leak, in which the udev device reference isn't released at the end of
running udevEventHandleCallback().

I'm happy to answer any questions about the patch, there is also a bit
more background at
https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/571093

---

>From 6c8183e83fbfeb031b16cf9ae2d41b16e3145378 Mon Sep 17 00:00:00 2001
From: Nigel Jones <dev nigelj com>
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;
 }

-- 
1.7.0.4


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