aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2026-09-14 22:33:01 +0200
committersaturneric <[email protected]>2026-09-14 22:33:01 +0200
commite4767d3ad88ddfb71262c3facdeaee63b3afc88c (patch)
tree1b7b4295516184baa7a6c0dde418020a207ef87c
parenttest(imap): cover folder status validation (diff)
downloadmodules-e4767d3ad88ddfb71262c3facdeaee63b3afc88c.tar.gz
modules-e4767d3ad88ddfb71262c3facdeaee63b3afc88c.zip
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
-rw-r--r--src/m_gpg_info/GnuPGInfoGatheringModule.cpp14
1 files changed, 10 insertions, 4 deletions
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());