Skip to content

Commit

Permalink
diff: fix textconv error zombies
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Sixt authored and Junio C Hamano committed Mar 30, 2010
1 parent 657ab61 commit da1fbed
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3865,6 +3865,7 @@ static char *run_textconv(const char *pgm, struct diff_filespec *spec,
const char **arg = argv;
struct child_process child;
struct strbuf buf = STRBUF_INIT;
int err = 0;

temp = prepare_temp_file(spec->path, spec);
*arg++ = pgm;
Expand All @@ -3875,16 +3876,20 @@ static char *run_textconv(const char *pgm, struct diff_filespec *spec,
child.use_shell = 1;
child.argv = argv;
child.out = -1;
if (start_command(&child) != 0 ||
strbuf_read(&buf, child.out, 0) < 0 ||
finish_command(&child) != 0) {
close(child.out);
strbuf_release(&buf);
if (start_command(&child)) {
remove_tempfile();
error("error running textconv command '%s'", pgm);
return NULL;
}

if (strbuf_read(&buf, child.out, 0) < 0)
err = error("error reading from textconv command '%s'", pgm);
close(child.out);

if (finish_command(&child) || err) {
strbuf_release(&buf);
remove_tempfile();
return NULL;
}
remove_tempfile();

return strbuf_detach(&buf, outsize);
Expand Down

0 comments on commit da1fbed

Please sign in to comment.