From ffbf34fb158f4e9099c66bd5fd68a68d3f6c4d5a Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Fri, 10 Nov 2023 08:05:09 +0100 Subject: [PATCH] Fix ModData bug when unloading a module for good: iterate unknown_list. When a module was unloaded (for good) that used MODDATATYPE_CLIENT or MODDATATYPE_LOCAL_CLIENT we walked the client_list/lclient_list and freed the moddata entry for all these clients, but we did not walk the unknown_list, so connections in process. That's bad, because sometimes such moddata is allocated in HOOKTYPE_HANDSHAKE or in other routines pre-connect and since we skipped freeing them while the module was still loaded, it means we leak memory since it is also not freed on user exit. Since unloading modules permanently is not a common procedure, combined with the timing of it happening during a handshake, it took a while before this issue was found (and then easily fixed). There's also another moddata issue, but that is for next commit. [skip ci] --- src/api-moddata.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/api-moddata.c b/src/api-moddata.c index 1dd503538..aa0767142 100644 --- a/src/api-moddata.c +++ b/src/api-moddata.c @@ -195,6 +195,12 @@ void unload_moddata_commit(ModDataInfo *md) md->free(&moddata_client(client, md)); memset(&moddata_client(client, md), 0, sizeof(ModData)); } + list_for_each_entry(client, &unknown_list, lclient_node) + { + if (md->free && moddata_client(client, md).ptr) + md->free(&moddata_client(client, md)); + memset(&moddata_client(client, md), 0, sizeof(ModData)); + } break; } case MODDATATYPE_LOCAL_CLIENT: @@ -206,6 +212,12 @@ void unload_moddata_commit(ModDataInfo *md) md->free(&moddata_local_client(client, md)); memset(&moddata_local_client(client, md), 0, sizeof(ModData)); } + list_for_each_entry(client, &unknown_list, lclient_node) + { + if (md->free && moddata_local_client(client, md).ptr) + md->free(&moddata_local_client(client, md)); + memset(&moddata_local_client(client, md), 0, sizeof(ModData)); + } break; } case MODDATATYPE_CHANNEL: