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

[libvirt] [PATCH] Don't leak memory if a cgroup is mounted multiple times



From: "Daniel P. Berrange" <berrange redhat com>

It is possible (expected/likely in Fedora 15) for a cgroup controller
to be mounted in multiple locations at the same time, due to bind
mounts. Currently we leak memory if this happens, because we overwrite
the previous 'mountPoint' string. Instead just accept the first match
we find.

* src/util/cgroup.c: Only accept first match for a cgroup
  controller mount
---
 src/util/cgroup.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index f3ec80f..c8d1f33 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -131,7 +131,12 @@ static int virCgroupDetectMounts(virCgroupPtr group)
                 } else {
                     len = strlen(tmp);
                 }
+                /* NB, the same controller can appear >1 time in mount list
+                 * due to bind mounts from one location to another. Pick the
+                 * first entry only
+                 */
                 if (typelen == len && STREQLEN(typestr, tmp, len) &&
+                    !group->controllers[i].mountPoint &&
                     !(group->controllers[i].mountPoint = strdup(entry.mnt_dir)))
                     goto no_memory;
                 tmp = next;
-- 
1.7.6


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