Fix possible memory leak setting invalid preference when loading a BoolPrefWidget from an XML file

Reported in #2782
This commit is contained in:
David Capello 2021-06-23 08:54:26 -03:00
parent 89f8e6f275
commit 6157b004e4

View File

@ -39,6 +39,7 @@
#include <cstdlib>
#include <cstring>
#include <limits>
#include <memory>
namespace app {
@ -202,9 +203,10 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
if (!widget) {
// Automatic bind <check> widget with bool preference option
if (pref) {
auto prefWidget = new BoolPrefWidget<CheckBox>("");
std::unique_ptr<BoolPrefWidget<CheckBox>> prefWidget(
new BoolPrefWidget<CheckBox>(""));
prefWidget->setPref(pref);
widget = prefWidget;
widget = prefWidget.release();
}
else {
widget = new CheckBox("");