fix memory leak in setup when datadir is invalid or setup failed

This commit is contained in:
Edward Ding
2018-10-26 15:08:56 -07:00
parent eae01d3e60
commit 363e83304a

View File

@@ -261,20 +261,22 @@ bool libpostal_setup_datadir(char *datadir) {
numex_path = path_join(3, datadir, LIBPOSTAL_NUMEX_SUBDIR, NUMEX_DATA_FILE);
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) {
@@ -289,7 +291,7 @@ bool libpostal_setup_datadir(char *datadir) {
free(address_dictionary_path);
}
return true;
return setup_succeed;
}
bool libpostal_setup(void) {