fclose(3) instead of pclose(3) as the latter seems to leak file descriptors
authorNikos Ntarmos <ntarmos@cs.uoi.gr>
Sun, 5 Dec 2010 03:57:35 +0000 (05:57 +0200)
committerPavel Labath <pavelo@centrum.sk>
Sun, 5 Dec 2010 20:08:20 +0000 (21:08 +0100)
Signed-off-by: Nikos Ntarmos <ntarmos@cs.uoi.gr>
Signed-off-by: Pavel Labath <pavelo@centrum.sk>

src/exec.c

index 5c9662c..c9e4261 100644 (file)
@@ -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';