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