fix memory leak

fix memory leak when channel error
This commit is contained in:
xqing2003 2018-06-06 22:11:55 +08:00 committed by GitHub
parent 7737917886
commit e40006058e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 6 deletions

View File

@ -70,7 +70,7 @@ void TcpConnection::process(int fd, int flags)
auto *result = _state->process(monitor, fd, flags);
// are we still valid
if (!monitor.valid())
if (!monitor.valid() && result != _state.get())
{
delete result;
return;
@ -79,11 +79,7 @@ void TcpConnection::process(int fd, int flags)
// skip if the same state is continued to be used, or when the process()
// method returns nullptr (which only happens when the object is destructed,
// and "this" is no longer valid)
if (!result || result == _state.get())
{
delete result;
return;
}
if (!result || result == _state.get()) return;
// replace it with the new implementation
_state.reset(result);
}