From 7737917886db51d74d5a9336e3893d05baa15454 Mon Sep 17 00:00:00 2001 From: xqing2003 Date: Fri, 1 Jun 2018 23:30:30 +0800 Subject: [PATCH] solve memory leak --- src/linux_tcp/tcpconnection.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/linux_tcp/tcpconnection.cpp b/src/linux_tcp/tcpconnection.cpp index b8f0cd1..184dabf 100644 --- a/src/linux_tcp/tcpconnection.cpp +++ b/src/linux_tcp/tcpconnection.cpp @@ -70,13 +70,20 @@ void TcpConnection::process(int fd, int flags) auto *result = _state->process(monitor, fd, flags); // are we still valid - if (!monitor.valid()) return; + if (!monitor.valid()) + { + delete result; + return; + } // 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()) return; - + if (!result || result == _state.get()) + { + delete result; + return; + } // replace it with the new implementation _state.reset(result); }