From 469eb2b4e00035939ab2621223321eef9dd0252e Mon Sep 17 00:00:00 2001 From: saturneric Date: Sat, 27 Jul 2024 11:29:51 +0200 Subject: [PATCH] fix: solve a memory leak issue --- include/GFModuleCommonUtils.hpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/include/GFModuleCommonUtils.hpp b/include/GFModuleCommonUtils.hpp index a300ddc..392aaef 100644 --- a/include/GFModuleCommonUtils.hpp +++ b/include/GFModuleCommonUtils.hpp @@ -97,11 +97,8 @@ inline auto QMapToGFModuleMetaDataList(const QMap& map) QByteArray const key = it.key().toUtf8(); QByteArray const value = it.value().toUtf8(); - new_node->key = new char[key.size() + 1]; - std::strcpy(const_cast(new_node->key), key.constData()); - - new_node->value = new char[value.size() + 1]; - std::strcpy(const_cast(new_node->value), value.constData()); + new_node->key = DUP(key); + new_node->value = DUP(value); new_node->next = nullptr; @@ -139,8 +136,8 @@ auto SecureCreateSharedObject(Args&&... args) -> std::shared_ptr { } } -inline auto CharArrayToQStringList(char** pl_components, int size) - -> QStringList { +inline auto CharArrayToQStringList(char** pl_components, + int size) -> QStringList { QStringList list; for (int i = 0; i < size; ++i) { list.append(QString::fromUtf8(pl_components[i]));