From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6FEA61F992 for ; Fri, 27 May 2016 06:17:41 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/3] httpd/async: prevent circular reference Date: Fri, 27 May 2016 06:17:36 +0000 Message-Id: <20160527061738.21132-2-e@80x24.org> In-Reply-To: <20160527061738.21132-1-e@80x24.org> References: <20160527061738.21132-1-e@80x24.org> List-Id: We must avoid circular references which can cause leaks in long-running processes. This callback is dangerous since it may never be called to properly terminate everything. --- lib/PublicInbox/HTTPD/Async.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm index 47ba27d..b00e637 100644 --- a/lib/PublicInbox/HTTPD/Async.pm +++ b/lib/PublicInbox/HTTPD/Async.pm @@ -10,6 +10,7 @@ use strict; use warnings; use base qw(Danga::Socket); use fields qw(cb cleanup); +use Scalar::Util qw(weaken); require PublicInbox::EvCleanup; sub new { @@ -25,11 +26,12 @@ sub new { sub async_pass { my ($self, $io, $fh, $bref) = @_; - my $restart_read = sub { $self->watch_read(1) }; # In case the client HTTP connection ($io) dies, it # will automatically close this ($self) object. $io->{forward} = $self; $fh->write($$bref); + weaken($self); + my $restart_read = sub { $self->watch_read(1) }; $self->{cb} = sub { my $r = sysread($self->{sock}, $$bref, 8192); if ($r) {