Merge pull request #391 from edding/fix_memory_leak

fix memory leak in setup when datadir is invalid or setup failed
This commit is contained in:
Al B
2025-02-08 12:03:59 -05:00
committed by GitHub

View File

@@ -297,19 +297,21 @@ bool libpostal_setup_datadir(char *datadir) {
address_dictionary_path = path_join(3, datadir, LIBPOSTAL_ADDRESS_EXPANSIONS_SUBDIR, ADDRESS_DICTIONARY_DATA_FILE);
}
bool setup_succeed = true;
if (!transliteration_module_setup(transliteration_path)) {
log_error("Error loading transliteration module, dir=%s\n", transliteration_path);
return false;
setup_succeed = false;
}
if (!numex_module_setup(numex_path)) {
if (setup_succeed && !numex_module_setup(numex_path)) {
log_error("Error loading numex module, dir=%s\n", numex_path);
return false;
setup_succeed = false;
}
if (!address_dictionary_module_setup(address_dictionary_path)) {
if (setup_succeed && !address_dictionary_module_setup(address_dictionary_path)) {
log_error("Error loading dictionary module, dir=%s\n", address_dictionary_path);
return false;
setup_succeed = false;
}
if (transliteration_path != NULL) {
@@ -324,7 +326,7 @@ bool libpostal_setup_datadir(char *datadir) {
free(address_dictionary_path);
}
return true;
return setup_succeed;
}
bool libpostal_setup(void) {