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