|
|
d7059b |
From 69bc94779c2f035a9fffdb5327a54c3aeca73ed5 Mon Sep 17 00:00:00 2001
|
|
|
d7059b |
From: Simon Kelley <simon@thekelleys.org.uk>
|
|
|
d7059b |
Date: Wed, 14 Aug 2019 20:44:50 +0100
|
|
|
d7059b |
Subject: [PATCH] Fix memory leak in helper.c
|
|
|
d7059b |
|
|
|
d7059b |
Thanks to Xu Mingjie <xumingjie1995@outlook.com> for spotting this.
|
|
|
d7059b |
---
|
|
|
d7059b |
src/helper.c | 12 +++++++++---
|
|
|
d7059b |
1 file changed, 9 insertions(+), 3 deletions(-)
|
|
|
d7059b |
|
|
|
d7059b |
diff --git a/src/helper.c b/src/helper.c
|
|
|
d7059b |
index 33ba120..c392eec 100644
|
|
|
d7059b |
--- a/src/helper.c
|
|
|
d7059b |
+++ b/src/helper.c
|
|
|
d7059b |
@@ -80,7 +80,8 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|
|
d7059b |
pid_t pid;
|
|
|
d7059b |
int i, pipefd[2];
|
|
|
d7059b |
struct sigaction sigact;
|
|
|
d7059b |
-
|
|
|
d7059b |
+ unsigned char *alloc_buff = NULL;
|
|
|
d7059b |
+
|
|
|
d7059b |
/* create the pipe through which the main program sends us commands,
|
|
|
d7059b |
then fork our process. */
|
|
|
d7059b |
if (pipe(pipefd) == -1 || !fix_fd(pipefd[1]) || (pid = fork()) == -1)
|
|
|
d7059b |
@@ -186,11 +187,16 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|
|
d7059b |
struct script_data data;
|
|
|
d7059b |
char *p, *action_str, *hostname = NULL, *domain = NULL;
|
|
|
d7059b |
unsigned char *buf = (unsigned char *)daemon->namebuff;
|
|
|
d7059b |
- unsigned char *end, *extradata, *alloc_buff = NULL;
|
|
|
d7059b |
+ unsigned char *end, *extradata;
|
|
|
d7059b |
int is6, err = 0;
|
|
|
d7059b |
int pipeout[2];
|
|
|
d7059b |
|
|
|
d7059b |
- free(alloc_buff);
|
|
|
d7059b |
+ /* Free rarely-allocated memory from previous iteration. */
|
|
|
d7059b |
+ if (alloc_buff)
|
|
|
d7059b |
+ {
|
|
|
d7059b |
+ free(alloc_buff);
|
|
|
d7059b |
+ alloc_buff = NULL;
|
|
|
d7059b |
+ }
|
|
|
d7059b |
|
|
|
d7059b |
/* we read zero bytes when pipe closed: this is our signal to exit */
|
|
|
d7059b |
if (!read_write(pipefd[0], (unsigned char *)&data, sizeof(data), 1))
|
|
|
d7059b |
--
|
|
|
d7059b |
2.21.1
|
|
|
d7059b |
|