--- src/exec.c.1 2014-05-21 11:14:24.477643257 +0200 +++ src/exec.c 2014-05-21 13:10:26.710163412 +0200 @@ -427,7 +427,7 @@ static int fork_child (program_list_t *p int status; int pid; - if (pl->pid != 0) + if (!pl || pl->pid != 0) return (-1); status = pipe (fd_pipe_in); @@ -466,6 +466,23 @@ static int fork_child (program_list_t *p int fd_num; int fd; + /* free memory in children */ + { + program_list_t *pl; + program_list_t *next; + pl = pl_head; + while (pl != NULL) + { + next = pl->next; + sfree (pl->exec); + sfree (pl->argv); + sfree (pl->user); + sfree (pl); + pl = next; + } /* while (pl) */ + pl_head = NULL; + } + /* Close all file descriptors but the pipe end we need. */ fd_num = getdtablesize (); for (fd = 0; fd < fd_num; fd++) @@ -546,16 +563,18 @@ static int parse_line (char *buffer) /* } } /* int parse_line }}} */ +#define _memmove(buffer, pbuffer, len) { \ + char tmp[1200]; \ + memcpy(tmp, pbuffer, len); \ + memcpy(buffer, tmp, len); \ +} + static void *exec_read_one (void *arg) /* {{{ */ { program_list_t *pl = (program_list_t *) arg; int fd, fd_err, highest_fd; fd_set fdset, copy; int status; - char buffer[1200]; /* if not completely read */ - char buffer_err[1024]; - char *pbuffer = buffer; - char *pbuffer_err = buffer_err; status = fork_child (pl, NULL, &fd, &fd_err); if (status < 0) @@ -564,6 +583,7 @@ static void *exec_read_one (void *arg) / pthread_mutex_lock (&pl_lock); pl->flags &= ~PL_RUNNING; pthread_mutex_unlock (&pl_lock); + sfree (arg); pthread_exit ((void *) 1); } pl->pid = status; @@ -583,6 +603,10 @@ static void *exec_read_one (void *arg) / while (1) { int len; + char buffer[1200]; /* if not completely read */ + char buffer_err[1024]; + char *pbuffer = buffer; + char *pbuffer_err = buffer_err; status = select (highest_fd + 1, ©, NULL, NULL, NULL); if (status < 0) @@ -623,7 +647,7 @@ static void *exec_read_one (void *arg) / if (pbuffer - buffer < len) { len -= pbuffer - buffer; - memmove(buffer, pbuffer, len); + _memmove(buffer, pbuffer, len); pbuffer = buffer + len; } else @@ -675,7 +699,7 @@ static void *exec_read_one (void *arg) / if (pbuffer_err - buffer_err < len) { len -= pbuffer_err - buffer_err; - memmove(buffer_err, pbuffer_err, len); + _memmove(buffer_err, pbuffer_err, len); pbuffer_err = buffer_err + len; } else @@ -805,6 +829,7 @@ static int exec_init (void) /* {{{ */ static int exec_read (void) /* {{{ */ { + int err; program_list_t *pl; for (pl = pl_head; pl != NULL; pl = pl->next) @@ -825,10 +850,13 @@ static int exec_read (void) /* {{{ */ } pl->flags |= PL_RUNNING; pthread_mutex_unlock (&pl_lock); - pthread_attr_init (&attr); - pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - pthread_create (&t, &attr, exec_read_one, (void *) pl); + err = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); + fprintf(stderr, ">>> pthread_attr_setdetachstate returns %d\n", err); + err = pthread_attr_setstacksize(&attr, (size_t)1024*1024); + fprintf(stderr, ">>> pthread_attr_setstacksize returns %d\n", err); + err = pthread_create (&t, &attr, exec_read_one, (void *) pl); + fprintf(stderr, ">>> pthread_create returns %d\n", err); pthread_attr_destroy (&attr); } /* for (pl) */ @@ -840,6 +868,7 @@ static int exec_notification (const noti { program_list_t *pl; program_list_and_notification_t *pln; + int err; for (pl = pl_head; pl != NULL; pl = pl->next) { @@ -871,8 +900,12 @@ static int exec_notification (const noti plugin_notification_meta_copy (&pln->n, n); pthread_attr_init (&attr); - pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - pthread_create (&t, &attr, exec_notification_one, (void *) pln); + err = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); + fprintf(stderr, ">>> pthread_attr_setdetachstate returns %d\n", err); + err = pthread_attr_setstacksize(&attr, (size_t)1024*1024); + fprintf(stderr, ">>> pthread_attr_setstacksize returns %d\n", err); + err = pthread_create (&t, &attr, exec_notification_one, (void *) pln); + fprintf(stderr, ">>> pthread_create returns %d\n", err); pthread_attr_destroy (&attr); } /* for (pl) */ @@ -895,6 +928,8 @@ static int exec_shutdown (void) /* {{{ * INFO ("exec plugin: Sent SIGTERM to %hu", (unsigned short int) pl->pid); } + sfree (pl->exec); + sfree (pl->argv); sfree (pl->user); sfree (pl);