fix: Memory leak after delete client #143

This commit is contained in:
yuanyuanxiang
2025-07-04 04:54:53 +08:00
parent 64bebb1b86
commit 7f5b409c5c
6 changed files with 27 additions and 11 deletions

View File

@@ -7,9 +7,10 @@
class IOCPUDPServer : public Server {
struct IO_CONTEXT {
OVERLAPPED ol;
CONTEXT_UDP* pContext;
IO_CONTEXT(CONTEXT_UDP* ctx) : ol({}), pContext(ctx) { }
OVERLAPPED ol = {};
CONTEXT_UDP* pContext = nullptr;
IO_CONTEXT() : ol({}), pContext(new CONTEXT_UDP) {
}
~IO_CONTEXT() {
SAFE_DELETE(pContext);
}
@@ -30,7 +31,7 @@ private:
void PostRecv();
IO_CONTEXT* AddCount(){
m_locker.lock();
IO_CONTEXT* ioCtx = new IO_CONTEXT(new CONTEXT_UDP());
IO_CONTEXT* ioCtx = new IO_CONTEXT();
ioCtx->pContext->InitMember(m_socket, this);
m_count++;
m_locker.unlock();