From 23a23a01f1dcec84bde48705bc9d78a8ca3febd1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 19 Feb 2018 06:58:42 -0500 Subject: [PATCH] [contextualprocess] Cleanup destructors - ValueCheck shouldn't own the pointer, since it's just a QPair and there are temporary copies made (e.g. in ContextualProcessBinding::append() ) and we get double-deletes. - Do deletion by hand; going full unique_ptr would be a bit overkill. --- .../contextualprocess/ContextualProcessJob.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/modules/contextualprocess/ContextualProcessJob.cpp b/src/modules/contextualprocess/ContextualProcessJob.cpp index facb93c41..a61a8bb3f 100644 --- a/src/modules/contextualprocess/ContextualProcessJob.cpp +++ b/src/modules/contextualprocess/ContextualProcessJob.cpp @@ -30,10 +30,6 @@ #include "utils/CommandList.h" #include "utils/Logger.h" -/** - * Passing a CommandList to ValueCheck gives ownership of the CommandList to - * the ValueCheck, which will delete the CommandList when needed. - */ struct ValueCheck : public QPair { ValueCheck( const QString& value, CalamaresUtils::CommandList* commands ) @@ -43,7 +39,9 @@ struct ValueCheck : public QPair ~ValueCheck() { - delete second; + // We don't own the commandlist, the binding holding this valuecheck + // does, so don't delete. This is closely tied to (temporaries created + // by) pass-by-value in QList::append(). } QString value() const { return first; } @@ -62,8 +60,7 @@ struct ContextualProcessBinding /** * @brief add commands to be executed when @p value is matched. * - * Ownership of the CommandList passes to the ValueCheck held - * by this binding. + * Ownership of the CommandList passes to this binding. */ void append( const QString& value, CalamaresUtils::CommandList* commands ) { @@ -95,6 +92,10 @@ struct ContextualProcessBinding ContextualProcessBinding::~ContextualProcessBinding() { wildcard = nullptr; + for ( const auto& c : checks ) + { + delete c.commands(); + } } ContextualProcessJob::ContextualProcessJob( QObject* parent )