Skip to content

Commit 3a0c2dc

Browse files
committed
Fix leak with HANDLE + send_headers
1 parent 448560f commit 3a0c2dc

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/AnyEvent/HTTP/Server.pm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ sub drop {
223223
my ($self,$id,$err) = @_;
224224
$err =~ s/\015//sg;
225225
#warn "Dropping connection $id: $err (by request from @{[ (caller)[1,2] ]})";# if DEBUG or $self->{debug};
226-
my $r = delete $self->{$id};
226+
my $r = delete $self->{$id} or return;
227227
$self->{active_connections}--;
228228
%{ $r } = () if $r;
229229

@@ -564,17 +564,16 @@ sub incoming {
564564
$h->on_drain(sub {
565565
$h->destroy;
566566
undef $h;
567-
$self->drop($id) if $self;
568567
});
569568
undef $h;
570569
}
571-
else {
572-
$self->drop($id) if $self;
573-
}
574570
}
575571
});
576572
$req->handle($h);
577573
$rv[1]->($h);
574+
$h->{__cnn_drop_guard} = guard {
575+
$self->drop($id) if $self;
576+
};
578577
weaken($req);
579578
%r = ( );
580579
return;

lib/AnyEvent/HTTP/Server/Req.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,11 @@ BEGIN {
540540
}
541541
elsif(defined $self->{chunked}) {
542542
${ $self->{reqcount} }--;
543+
# warn "sent body with non-chunked (wr=$self->{writer}) (".$self->connection.")\n";
544+
if( $self->{writer} ) {
545+
$self->{writer}->(\undef) if $self->connection eq 'close' or $self->server->{graceful};
546+
delete $self->{writer};
547+
}
543548
undef $self->{chunked};
544549
}
545550
else {

0 commit comments

Comments
 (0)