1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-06 00:13:33 +00:00

Moved where metadata is instantiated, to prevent memory leak in error cases

This commit is contained in:
Bryan Roe
2022-08-11 14:56:05 -07:00
parent 63f420398b
commit f39cfd6773

View File

@@ -327,6 +327,8 @@ void ILibAsyncServerSocket_PostSelect(void* socketModule, int slct, fd_set *read
void ILibAsyncServerSocket_Destroy(void *socketModule)
{
struct ILibAsyncServerSocketModule *module =(struct ILibAsyncServerSocketModule*)socketModule;
ILibMemory_Free(module->ChainLink.MetaData);
module->ChainLink.MetaData = NULL;
free(module->AsyncSockets);
module->AsyncSockets = NULL;
@@ -637,7 +639,6 @@ ILibAsyncServerSocket_ServerModule ILibCreateAsyncServerSocketModuleWithMemoryEx
// Instantiate a new AsyncServer module
RetVal = (struct ILibAsyncServerSocketModule*)ILibChain_Link_Allocate(sizeof(struct ILibAsyncServerSocketModule), ServerUserMappedMemorySize);
RetVal->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibAsyncServerSocket");
RetVal->ChainLink.PreSelectHandler = &ILibAsyncServerSocket_PreSelect;
RetVal->ChainLink.PostSelectHandler = &ILibAsyncServerSocket_PostSelect;
RetVal->ChainLink.DestroyHandler = &ILibAsyncServerSocket_Destroy;
@@ -738,6 +739,7 @@ ILibAsyncServerSocket_ServerModule ILibCreateAsyncServerSocketModuleWithMemoryEx
#pragma warning( push, 3 ) // warning C4127: conditional expression is constant
#endif
RetVal->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibAsyncServerSocket");
ILibAddToChain(Chain, RetVal);
return RetVal;
}