From f3e7191ae86b96a8551c7eff83ec7a604cf13e73 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Fri, 30 Jun 2017 08:41:34 +0000 Subject: [PATCH] TcpServerUtils.pm: avoid memory leak, delete attribtue for temprary connections (Forum #73490) git-svn-id: https://svn.fhem.de/fhem/trunk@14602 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/01_FHEMWEB.pm | 19 ++++++++----------- fhem/FHEM/TcpServerUtils.pm | 2 ++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index 36a4eeef2..294885870 100755 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -521,8 +521,8 @@ FW_Read($$) if(grep { $p->{$_}{FORKABLE} && $arg =~ m+^$FW_ME$_+ } keys %{$p}) { my $pid = fhemFork(); if($pid) { # success, parent - use constant PRIO_PROCESS => 0; - setpriority(PRIO_PROCESS, $pid, getpriority(PRIO_PROCESS,$pid) + $pf) + use constant PRIO_PROCESS => 0; + setpriority(PRIO_PROCESS, $pid, getpriority(PRIO_PROCESS,$pid) + $pf) if($^O !~ m/Win/); # a) while child writes a new request might arrive if client uses # pipelining or @@ -530,14 +530,15 @@ FW_Read($$) # to socket # -> have to close socket in parent... so that its only used in this # child. - TcpServer_Disown( $hash ); - delete($defs{$name}); + TcpServer_Disown( $hash ); + delete($defs{$name}); + delete($attr{$name}); FW_Read($hash, 1) if($hash->{BUF}); - return; + return; } elsif(defined($pid)){ # child delete $hash->{BUF}; - $hash->{isChild} = 1; + $hash->{isChild} = 1; } # fork failed and continue in parent } @@ -580,7 +581,6 @@ FW_Read($$) if(!$hash->{isChild}); TcpServer_Close( $hash ); FW_closeConn($hash); - delete($defs{$name}); } } @@ -706,7 +706,6 @@ FW_closeConn($) $FW_userAgent && $FW_userAgent=~m/(iPhone|iPad|iPod)/); if(!$FW_httpheader{Connection} || $cc) { TcpServer_Close($hash); - delete($defs{$hash->{NAME}}); } } @@ -2786,7 +2785,6 @@ FW_logInform($$) if(!FW_addToWritebuffer($ntfy, "
$msg
") ){ TcpServer_Close($ntfy); delete $logInform{$me}; - delete $defs{$me}; } } @@ -2910,7 +2908,6 @@ FW_Notify($$) my $name = $ntfy->{NAME}; Log3 $name, 4, "Closing connection $name due to full buffer in FW_Notify"; TcpServer_Close($ntfy); - delete($defs{$name}); } } @@ -2938,7 +2935,6 @@ FW_directNotify($@) # Notify without the event overhead (Forum #31293) my $name = $ntfy->{NAME}; Log3 $name, 4, "Closing connection $name due to full buffer in FW_Notify"; TcpServer_Close($ntfy); - delete($defs{$name}); } } } @@ -3127,6 +3123,7 @@ FW_closeInactiveClients() Log3 $FW_wname, 4, "Closing inactive connection $dev"; FW_Undef($defs{$dev}, ""); delete $defs{$dev}; + delete $attr{$dev}; } InternalTimer($now+60, "FW_closeInactiveClients", 0, 0); } diff --git a/fhem/FHEM/TcpServerUtils.pm b/fhem/FHEM/TcpServerUtils.pm index 459f9a85a..dc9d907c5 100644 --- a/fhem/FHEM/TcpServerUtils.pm +++ b/fhem/FHEM/TcpServerUtils.pm @@ -181,6 +181,8 @@ TcpServer_Close($) delete($hash->{CD}); delete($selectlist{$name}); delete($hash->{FD}); # Avoid Read->Close->Write + delete $attr{$name}; + delete $defs{$name}; } if(defined($hash->{SERVERSOCKET})) { # Server close($hash->{SERVERSOCKET});