From 974fe13d2f3bbba01910d09f5d1a3d36dfff41f2 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 2 Mar 2022 22:32:36 -0500 Subject: [PATCH] Increase ref counter of module JSON in ModuleWidget::pasteJsonAction() when giving shared ownership to history::ModuleChange action. --- src/app/ModuleWidget.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index b7679b36..76a1b3ae 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -506,13 +506,13 @@ bool ModuleWidget::pasteJsonAction(json_t* moduleJ) { engine::Module::jsonStripIds(moduleJ); json_t* oldModuleJ = toJson(); + DEFER({json_decref(oldModuleJ);}); try { fromJson(moduleJ); } catch (Exception& e) { WARN("%s", e.what()); - json_decref(oldModuleJ); return false; } @@ -520,7 +520,9 @@ bool ModuleWidget::pasteJsonAction(json_t* moduleJ) { history::ModuleChange* h = new history::ModuleChange; h->name = "paste module preset"; h->moduleId = module->id; + json_incref(oldModuleJ); h->oldModuleJ = oldModuleJ; + json_incref(moduleJ); h->newModuleJ = moduleJ; APP->history->push(h); return true;