X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FGetlineBody.pm;h=7fcd7c03554cb7791136ad4a14dc3f917b890f8c;hb=3d41aa23f35501ca92aab8aa42980fa73f7fa74f;hp=4f8765bbe6e7bfd37d67f23a7343fe99535b389a;hpb=79e11eea11dd561301a05c42ba824a7d352bd398;p=public-inbox.git
diff --git a/lib/PublicInbox/GetlineBody.pm b/lib/PublicInbox/GetlineBody.pm
index 4f8765bb..7fcd7c03 100644
--- a/lib/PublicInbox/GetlineBody.pm
+++ b/lib/PublicInbox/GetlineBody.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2016 all contributors
+# Copyright (C) 2016-2018 all contributors
# License: AGPL-3.0+
# Wrap a pipe or file for PSGI streaming response bodies and calls the
@@ -13,19 +13,23 @@ sub new {
bless { rpipe => $rpipe, end => $end, buf => $buf }, $class;
}
+# close should always be called after getline returns undef,
+# but a client aborting a connection can ruin our day; so lets
+# hope our underlying PSGI server does not leak references, here.
sub DESTROY { $_[0]->close }
sub getline {
my ($self) = @_;
- my $buf = delete $self->{buf};
+ my $buf = delete $self->{buf}; # initial buffer
defined $buf ? $buf : $self->{rpipe}->getline;
}
sub close {
my ($self) = @_;
- delete $self->{rpipe};
- my $end = delete $self->{end} or return;
- $end->();
+ my $rpipe = delete $self->{rpipe};
+ close $rpipe if $rpipe;
+ my $end = delete $self->{end};
+ $end->() if $end;
}
1;