]>
Commit | Line | Data |
---|---|---|
0d386a51 WB |
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 | |
5 | ||
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' | |
12 | to realloc(). | |
13 | ||
14 | Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com> | |
15 | --- | |
16 | lxcfs.c | 2 +- | |
17 | 1 file changed, 1 insertion(+), 1 deletion(-) | |
18 | ||
19 | diff --git a/lxcfs.c b/lxcfs.c | |
20 | index 8605000..d738e79 100644 | |
21 | --- a/lxcfs.c | |
22 | +++ b/lxcfs.c | |
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) { | |
26 | do { | |
27 | - d = realloc(d, *asz + BUF_RESERVE_SIZE); | |
28 | + d = realloc(*src, *asz + BUF_RESERVE_SIZE); | |
29 | } while (!d); | |
30 | *src = d; | |
31 | *asz += BUF_RESERVE_SIZE; | |
32 | -- | |
33 | 2.1.4 | |
34 |