mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-20 07:16:03 +00:00
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
This commit is contained in:
parent
66172f24cb
commit
f3e7191ae8
@ -521,8 +521,8 @@ FW_Read($$)
|
|||||||
if(grep { $p->{$_}{FORKABLE} && $arg =~ m+^$FW_ME$_+ } keys %{$p}) {
|
if(grep { $p->{$_}{FORKABLE} && $arg =~ m+^$FW_ME$_+ } keys %{$p}) {
|
||||||
my $pid = fhemFork();
|
my $pid = fhemFork();
|
||||||
if($pid) { # success, parent
|
if($pid) { # success, parent
|
||||||
use constant PRIO_PROCESS => 0;
|
use constant PRIO_PROCESS => 0;
|
||||||
setpriority(PRIO_PROCESS, $pid, getpriority(PRIO_PROCESS,$pid) + $pf)
|
setpriority(PRIO_PROCESS, $pid, getpriority(PRIO_PROCESS,$pid) + $pf)
|
||||||
if($^O !~ m/Win/);
|
if($^O !~ m/Win/);
|
||||||
# a) while child writes a new request might arrive if client uses
|
# a) while child writes a new request might arrive if client uses
|
||||||
# pipelining or
|
# pipelining or
|
||||||
@ -530,14 +530,15 @@ FW_Read($$)
|
|||||||
# to socket
|
# to socket
|
||||||
# -> have to close socket in parent... so that its only used in this
|
# -> have to close socket in parent... so that its only used in this
|
||||||
# child.
|
# child.
|
||||||
TcpServer_Disown( $hash );
|
TcpServer_Disown( $hash );
|
||||||
delete($defs{$name});
|
delete($defs{$name});
|
||||||
|
delete($attr{$name});
|
||||||
FW_Read($hash, 1) if($hash->{BUF});
|
FW_Read($hash, 1) if($hash->{BUF});
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} elsif(defined($pid)){ # child
|
} elsif(defined($pid)){ # child
|
||||||
delete $hash->{BUF};
|
delete $hash->{BUF};
|
||||||
$hash->{isChild} = 1;
|
$hash->{isChild} = 1;
|
||||||
|
|
||||||
} # fork failed and continue in parent
|
} # fork failed and continue in parent
|
||||||
}
|
}
|
||||||
@ -580,7 +581,6 @@ FW_Read($$)
|
|||||||
if(!$hash->{isChild});
|
if(!$hash->{isChild});
|
||||||
TcpServer_Close( $hash );
|
TcpServer_Close( $hash );
|
||||||
FW_closeConn($hash);
|
FW_closeConn($hash);
|
||||||
delete($defs{$name});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -706,7 +706,6 @@ FW_closeConn($)
|
|||||||
$FW_userAgent && $FW_userAgent=~m/(iPhone|iPad|iPod)/);
|
$FW_userAgent && $FW_userAgent=~m/(iPhone|iPad|iPod)/);
|
||||||
if(!$FW_httpheader{Connection} || $cc) {
|
if(!$FW_httpheader{Connection} || $cc) {
|
||||||
TcpServer_Close($hash);
|
TcpServer_Close($hash);
|
||||||
delete($defs{$hash->{NAME}});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2786,7 +2785,6 @@ FW_logInform($$)
|
|||||||
if(!FW_addToWritebuffer($ntfy, "<div class='fhemlog'>$msg</div>") ){
|
if(!FW_addToWritebuffer($ntfy, "<div class='fhemlog'>$msg</div>") ){
|
||||||
TcpServer_Close($ntfy);
|
TcpServer_Close($ntfy);
|
||||||
delete $logInform{$me};
|
delete $logInform{$me};
|
||||||
delete $defs{$me};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2910,7 +2908,6 @@ FW_Notify($$)
|
|||||||
my $name = $ntfy->{NAME};
|
my $name = $ntfy->{NAME};
|
||||||
Log3 $name, 4, "Closing connection $name due to full buffer in FW_Notify";
|
Log3 $name, 4, "Closing connection $name due to full buffer in FW_Notify";
|
||||||
TcpServer_Close($ntfy);
|
TcpServer_Close($ntfy);
|
||||||
delete($defs{$name});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2938,7 +2935,6 @@ FW_directNotify($@) # Notify without the event overhead (Forum #31293)
|
|||||||
my $name = $ntfy->{NAME};
|
my $name = $ntfy->{NAME};
|
||||||
Log3 $name, 4, "Closing connection $name due to full buffer in FW_Notify";
|
Log3 $name, 4, "Closing connection $name due to full buffer in FW_Notify";
|
||||||
TcpServer_Close($ntfy);
|
TcpServer_Close($ntfy);
|
||||||
delete($defs{$name});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3127,6 +3123,7 @@ FW_closeInactiveClients()
|
|||||||
Log3 $FW_wname, 4, "Closing inactive connection $dev";
|
Log3 $FW_wname, 4, "Closing inactive connection $dev";
|
||||||
FW_Undef($defs{$dev}, "");
|
FW_Undef($defs{$dev}, "");
|
||||||
delete $defs{$dev};
|
delete $defs{$dev};
|
||||||
|
delete $attr{$dev};
|
||||||
}
|
}
|
||||||
InternalTimer($now+60, "FW_closeInactiveClients", 0, 0);
|
InternalTimer($now+60, "FW_closeInactiveClients", 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -181,6 +181,8 @@ TcpServer_Close($)
|
|||||||
delete($hash->{CD});
|
delete($hash->{CD});
|
||||||
delete($selectlist{$name});
|
delete($selectlist{$name});
|
||||||
delete($hash->{FD}); # Avoid Read->Close->Write
|
delete($hash->{FD}); # Avoid Read->Close->Write
|
||||||
|
delete $attr{$name};
|
||||||
|
delete $defs{$name};
|
||||||
}
|
}
|
||||||
if(defined($hash->{SERVERSOCKET})) { # Server
|
if(defined($hash->{SERVERSOCKET})) { # Server
|
||||||
close($hash->{SERVERSOCKET});
|
close($hash->{SERVERSOCKET});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user