mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-04 22:31:02 +00:00
Fix a small memory leak when creating default enum list options (#16133)
Fix memory leak in ConfigOptionDef::create_default_option for enum lists
This commit is contained in:
@@ -326,17 +326,13 @@ ConfigOption* ConfigOptionDef::create_default_option() const
|
||||
return new ConfigOptionEnumGeneric(this->enum_keys_map, this->default_value->getInt());
|
||||
|
||||
if (type == coEnums) {
|
||||
auto dft = this->default_value->clone();
|
||||
if (dft->nullable()) {
|
||||
ConfigOptionEnumsGenericNullable *opt = dynamic_cast<ConfigOptionEnumsGenericNullable *>(this->default_value->clone());
|
||||
opt->keys_map = this->enum_keys_map;
|
||||
return opt;
|
||||
} else {
|
||||
ConfigOptionEnumsGeneric *opt = dynamic_cast<ConfigOptionEnumsGeneric *>(this->default_value->clone());
|
||||
opt->keys_map = this->enum_keys_map;
|
||||
return opt;
|
||||
}
|
||||
delete dft;
|
||||
// Enum list defaults are built without a keys map, which the copy needs to deserialize and serialize names.
|
||||
ConfigOption *opt = this->default_value->clone();
|
||||
if (auto *nullable_enums = dynamic_cast<ConfigOptionEnumsGenericNullable *>(opt))
|
||||
nullable_enums->keys_map = this->enum_keys_map;
|
||||
else if (auto *enums = dynamic_cast<ConfigOptionEnumsGeneric *>(opt))
|
||||
enums->keys_map = this->enum_keys_map;
|
||||
return opt;
|
||||
}
|
||||
|
||||
return this->default_value->clone();
|
||||
|
||||
@@ -1477,3 +1477,21 @@ TEST_CASE("A static config applied onto a config of another type falls back to a
|
||||
dynamic.apply(region);
|
||||
CHECK(dynamic.opt_serialize("sparse_infill_pattern") == "gyroid");
|
||||
}
|
||||
|
||||
TEST_CASE("Default options of enum lists get their definition's keys map", "[Config]")
|
||||
{
|
||||
size_t enum_lists = 0;
|
||||
for (const auto &[key, def] : print_config_def.options) {
|
||||
if (def.type != coEnums || !def.default_value)
|
||||
continue;
|
||||
INFO(key);
|
||||
const std::unique_ptr<ConfigOption> opt(def.create_default_option());
|
||||
CHECK(*opt == *def.default_value);
|
||||
const auto *nullable_enums = dynamic_cast<const ConfigOptionEnumsGenericNullable *>(opt.get());
|
||||
const auto *enums = dynamic_cast<const ConfigOptionEnumsGeneric *>(opt.get());
|
||||
REQUIRE((nullable_enums != nullptr) != (enums != nullptr));
|
||||
CHECK((nullable_enums != nullptr ? nullable_enums->keys_map : enums->keys_map) == def.enum_keys_map);
|
||||
++enum_lists;
|
||||
}
|
||||
CHECK(enum_lists > 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user