Skip to content

Commit 7fcbd37

Browse files
pcloudsgitster
authored andcommitted
upload-pack: make check_non_tip() clean things up on error
On error check_non_tip() will die and not closing file descriptors is no big deal. The next patch will split the majority of this function out for reuse in other cases, where die() may not be the only outcome. Same story for popping SIGPIPE out of the signal chain. So let's make sure we clean things up properly first. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6e414e3 commit 7fcbd37

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

upload-pack.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -475,16 +475,16 @@ static void check_non_tip(void)
475475
cmd.in = -1;
476476
cmd.out = -1;
477477

478-
if (start_command(&cmd))
479-
goto error;
480-
481478
/*
482-
* If rev-list --stdin encounters an unknown commit, it
483-
* terminates, which will cause SIGPIPE in the write loop
479+
* If the next rev-list --stdin encounters an unknown commit,
480+
* it terminates, which will cause SIGPIPE in the write loop
484481
* below.
485482
*/
486483
sigchain_push(SIGPIPE, SIG_IGN);
487484

485+
if (start_command(&cmd))
486+
goto error;
487+
488488
namebuf[0] = '^';
489489
namebuf[41] = '\n';
490490
for (i = get_max_object_index(); 0 < i; ) {
@@ -507,8 +507,7 @@ static void check_non_tip(void)
507507
goto error;
508508
}
509509
close(cmd.in);
510-
511-
sigchain_pop(SIGPIPE);
510+
cmd.in = -1;
512511

513512
/*
514513
* The commits out of the rev-list are not ancestors of
@@ -518,6 +517,7 @@ static void check_non_tip(void)
518517
if (i)
519518
goto error;
520519
close(cmd.out);
520+
cmd.out = -1;
521521

522522
/*
523523
* rev-list may have died by encountering a bad commit
@@ -527,10 +527,19 @@ static void check_non_tip(void)
527527
if (finish_command(&cmd))
528528
goto error;
529529

530+
sigchain_pop(SIGPIPE);
531+
530532
/* All the non-tip ones are ancestors of what we advertised */
531533
return;
532534

533535
error:
536+
sigchain_pop(SIGPIPE);
537+
538+
if (cmd.in >= 0)
539+
close(cmd.in);
540+
if (cmd.out >= 0)
541+
close(cmd.out);
542+
534543
/* Pick one of them (we know there at least is one) */
535544
for (i = 0; i < want_obj.nr; i++) {
536545
o = want_obj.objects[i].item;

0 commit comments

Comments
 (0)