]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
fix leak in realloc loop in must_strcat_pid
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 7 Jan 2016 11:59:53 +0000 (12:59 +0100)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 7 Jan 2016 19:13:27 +0000 (11:13 -0800)
If the first realloc() call fails then 'd' becomes NULL,
subsequent realloc() retries will behave like malloc() and
the the original src pointer is never freed. Further more
the newly allocated data then contains uninitialized data
where the previous pids had been stored.
Avoid this by passing the the original pointer from '*src'
to realloc().

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
lxcfs.c

diff --git a/lxcfs.c b/lxcfs.c
index 860500030e29e51d2ca576d2ba61c3352416d4eb..d738e79f24ec3a1737f658387907035d2ef88985 100644 (file)
--- a/lxcfs.c
+++ b/lxcfs.c
@@ -87,7 +87,7 @@ static void must_strcat_pid(char **src, size_t *sz, size_t *asz, pid_t pid)
                *asz = BUF_RESERVE_SIZE;
        } else if (tmplen + *sz + 1 >= *asz) {
                do {
-                       d = realloc(d, *asz + BUF_RESERVE_SIZE);
+                       d = realloc(*src, *asz + BUF_RESERVE_SIZE);
                } while (!d);
                *src = d;
                *asz += BUF_RESERVE_SIZE;