>From ea95aa0c00c05a07518126df51db3e6ea6e4248b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Sun, 19 Aug 2018 12:11:46 -0300 Subject: [PATCH] filtering: wait for the sending process to terminate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So that it will release its resources. This fixes https://savannah.gnu.org/bugs/?54499. Signed-off-by: Marco Diego Aurélio Mesquita --- src/text.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/text.c b/src/text.c index b5269029..4e65f3cb 100644 --- a/src/text.c +++ b/src/text.c @@ -1127,6 +1127,7 @@ bool execute_command(const char *command) /* Original and temporary handlers for SIGINT. */ bool setup_failed = FALSE; /* Whether setting up the temporary SIGINT handler failed. */ + int pid_of_out_process = -1; /* Create a pipe to read the command's output from, and, if needed, * a pipe to feed the command's input through. */ @@ -1196,7 +1197,7 @@ bool execute_command(const char *command) update_undo(CUT); } - if (fork() == 0) { + if ((pid_of_out_process = fork()) == 0) { close(to_fd[0]); send_data(cutbuffer != NULL ? cutbuffer : openfile->fileage, to_fd[1]); close(to_fd[1]); @@ -1241,7 +1242,10 @@ bool execute_command(const char *command) openfile->undotop->strdata = mallocstrcpy(NULL, _("filtering")); } - if (wait(NULL) == -1) + if (should_pipe && waitpid(pid_of_out_process, NULL, 0) == -1) + nperror("wait"); + + if (waitpid(pid_of_command, NULL, 0) == -1) nperror("wait"); /* If it was changed, restore the handler for SIGINT. */ -- 2.11.0