]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei_to_mail: drop awkward duplication of $lei object
authorEric Wong <e@80x24.org>
Fri, 22 Sep 2023 21:13:15 +0000 (21:13 +0000)
committerEric Wong <e@80x24.org>
Fri, 22 Sep 2023 22:39:39 +0000 (22:39 +0000)
Our awaitpid API now exists and ProcessPipe uses it, so it's
immune to cyclic references.  Thus there's no need to create
a duplicate of the lei object to prevent leaks.

lib/PublicInbox/LeiToMail.pm

index 7c7967c857ca9c76b04800e38ec6e4ad4db3debd..4adcc33e3260b43e8a41e2eb14eac89217dfb429 100644 (file)
@@ -151,10 +151,9 @@ sub git_to_mail { # git->cat_async callback
 }
 
 sub reap_compress { # awaitpid callback
-       my ($pid, $lei) = @_;
-       my $cmd = delete $lei->{"pid.$pid"};
-       return if $? == 0;
-       $lei->fail($?, "@$cmd failed");
+       my ($pid, $lei, $cmd, $old_out) = @_;
+       $lei->{1} = $old_out;
+       $lei->fail($?, "@$cmd failed") if $?;
 }
 
 sub _post_augment_mbox { # open a compressor process from top-level process
@@ -165,9 +164,8 @@ sub _post_augment_mbox { # open a compressor process from top-level process
        my $rdr = { 0 => $r, 1 => $lei->{1}, 2 => $lei->{2}, pgid => 0 };
        my $pid = spawn($cmd, undef, $rdr);
        my $pp = gensym;
-       my $dup = bless { "pid.$pid" => $cmd }, ref($lei);
-       $dup->{$_} = $lei->{$_} for qw(2 sock);
-       tie *$pp, 'PublicInbox::ProcessPipe', $pid, $w, \&reap_compress, $dup;
+       tie *$pp, 'PublicInbox::ProcessPipe', $pid, $w,
+                       \&reap_compress, $lei, $cmd, $lei->{1};
        $lei->{1} = $pp;
 }