1 From cc1d9baadd760a3e6fc757d31569fbf46ad37dbd Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Thu, 7 Jan 2016 11:32:59 +0100
4 Subject: [PATCH lxcfs 3/5] fix leak in realloc loop in must_strcat_pid
6 If the first realloc() call fails then 'd' becomes NULL,
7 subsequent realloc() retries will behave like malloc() and
8 the the original src pointer is never freed. Further more
9 the newly allocated data then contains uninitialized data
10 where the previous pids had been stored.
11 Avoid this by passing the the original pointer from '*src'
14 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
17 1 file changed, 1 insertion(+), 1 deletion(-)
19 diff --git a/lxcfs.c b/lxcfs.c
20 index 8605000..d738e79 100644
23 @@ -87,7 +87,7 @@ static void must_strcat_pid(char **src, size_t *sz, size_t *asz, pid_t pid)
24 *asz = BUF_RESERVE_SIZE;
25 } else if (tmplen + *sz + 1 >= *asz) {
27 - d = realloc(d, *asz + BUF_RESERVE_SIZE);
28 + d = realloc(*src, *asz + BUF_RESERVE_SIZE);
31 *asz += BUF_RESERVE_SIZE;