Skip to content

Commit da1fbed

Browse files
j6tgitster
authored andcommitted
diff: fix textconv error zombies
To make the code simpler, run_textconv lumps all of its error checking into one conditional. However, the short-circuit means that an error in reading will prevent us from calling finish_command, leaving a zombie child. Clean up properly after errors. Based-on-work-by: Jeff King <[email protected]> Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 657ab61 commit da1fbed

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

diff.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3865,6 +3865,7 @@ static char *run_textconv(const char *pgm, struct diff_filespec *spec,
38653865
const char **arg = argv;
38663866
struct child_process child;
38673867
struct strbuf buf = STRBUF_INIT;
3868+
int err = 0;
38683869

38693870
temp = prepare_temp_file(spec->path, spec);
38703871
*arg++ = pgm;
@@ -3875,16 +3876,20 @@ static char *run_textconv(const char *pgm, struct diff_filespec *spec,
38753876
child.use_shell = 1;
38763877
child.argv = argv;
38773878
child.out = -1;
3878-
if (start_command(&child) != 0 ||
3879-
strbuf_read(&buf, child.out, 0) < 0 ||
3880-
finish_command(&child) != 0) {
3881-
close(child.out);
3882-
strbuf_release(&buf);
3879+
if (start_command(&child)) {
38833880
remove_tempfile();
3884-
error("error running textconv command '%s'", pgm);
38853881
return NULL;
38863882
}
3883+
3884+
if (strbuf_read(&buf, child.out, 0) < 0)
3885+
err = error("error reading from textconv command '%s'", pgm);
38873886
close(child.out);
3887+
3888+
if (finish_command(&child) || err) {
3889+
strbuf_release(&buf);
3890+
remove_tempfile();
3891+
return NULL;
3892+
}
38883893
remove_tempfile();
38893894

38903895
return strbuf_detach(&buf, outsize);

0 commit comments

Comments
 (0)