From e4767d3ad88ddfb71262c3facdeaee63b3afc88c Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 14 Sep 2026 22:33:01 +0200 Subject: fix(gpg): release gathered component data - use CharArrayToQStringList to free the component array and strings - duplicate component JSON before parsing to release caller-owned data - prevent leaks during repeated GnuPG information gathering --- src/m_gpg_info/GnuPGInfoGatheringModule.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/m_gpg_info') diff --git a/src/m_gpg_info/GnuPGInfoGatheringModule.cpp b/src/m_gpg_info/GnuPGInfoGatheringModule.cpp index e2d3012..56f3c80 100644 --- a/src/m_gpg_info/GnuPGInfoGatheringModule.cpp +++ b/src/m_gpg_info/GnuPGInfoGatheringModule.cpp @@ -237,9 +237,11 @@ auto StartGatheringAllGnuPGInfo() -> int { &components_c_array); if (components_c_array == nullptr || ret == 0) return -1; - QStringList components; - auto *p_a = components_c_array; - for (int i = 0; i < ret; i++) components.append(QString::fromUtf8(p_a[i])); + // Takes ownership of every element AND of the array itself. The hand + // rolled loop this replaces copied the strings out and freed neither, so + // the whole array leaked once per gathering pass -- the identical call in + // GnupgTab.cpp was already using this helper. + QStringList components = CharArrayToQStringList(components_c_array, ret); for (const auto &component : components) { const auto *component_info_json = GFModuleRetrieveRTValueOrDefault( @@ -248,8 +250,12 @@ auto StartGatheringAllGnuPGInfo() -> int { if (component_info_json == nullptr) continue; + // Caller-owned, so take it: this used to be read and dropped, leaking one + // JSON document per component per pass. + const auto component_info_raw = UDUP(component_info_json); + auto jsonlized_component_info = - QJsonDocument::fromJson(component_info_json); + QJsonDocument::fromJson(component_info_raw.toUtf8()); assert(jsonlized_component_info.isObject()); auto component_info = GpgComponentInfo(jsonlized_component_info.object()); -- cgit