[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.
main
Adriaan de Groot 7 years ago
parent 87e2f13dc2
commit 23a23a01f1

@ -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<QString, CalamaresUtils::CommandList*>
{
ValueCheck( const QString& value, CalamaresUtils::CommandList* commands )
@ -43,7 +39,9 @@ struct ValueCheck : public QPair<QString, CalamaresUtils::CommandList*>
~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 )

Loading…
Cancel
Save