From: Nikos Ntarmos Date: Sun, 5 Dec 2010 03:57:35 +0000 (+0200) Subject: fclose(3) instead of pclose(3) as the latter seems to leak file descriptors X-Git-Url: http://git.maemo.org/git/?p=monky;a=commitdiff_plain;h=da4f602694c3083a131b2f58a502c25a7febb76e fclose(3) instead of pclose(3) as the latter seems to leak file descriptors Signed-off-by: Nikos Ntarmos Signed-off-by: Pavel Labath --- diff --git a/src/exec.c b/src/exec.c index 5c9662c..c9e4261 100644 --- a/src/exec.c +++ b/src/exec.c @@ -93,6 +93,7 @@ static FILE* pid_popen(const char *command, const char *mode, pid_t *child) { } else { close(1); } + close(parentend); dup(childend); //by dupping childend, the returned fd will have close-on-exec turned off execl("/bin/sh", "sh", "-c", command, (char *) NULL); _exit(EXIT_FAILURE); //child should die here, (normally execl will take care of this but it can fail) @@ -156,7 +157,7 @@ static inline void read_exec(const char *data, char *buf, const int size, const int length; length = fread(buf, 1, size, fp); - pclose(fp); + fclose(fp); buf[length] = '\0'; if (length > 0 && buf[length - 1] == '\n') { buf[length - 1] = '\0'; @@ -320,7 +321,7 @@ void print_execpi(struct text_object *obj, char *p, int p_max_size) ed->buffer = malloc(text_buffer_size); length = fread(ed->buffer, 1, text_buffer_size, fp); - pclose(fp); + fclose(fp); output = ed->buffer; output[length] = '\0';