fix memory leak in setup when datadir is invalid or setup failed
This commit is contained in:
@@ -261,20 +261,22 @@ bool libpostal_setup_datadir(char *datadir) {
|
|||||||
numex_path = path_join(3, datadir, LIBPOSTAL_NUMEX_SUBDIR, NUMEX_DATA_FILE);
|
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);
|
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)) {
|
if (!transliteration_module_setup(transliteration_path)) {
|
||||||
log_error("Error loading transliteration module, dir=%s\n", 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);
|
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);
|
log_error("Error loading dictionary module, dir=%s\n", address_dictionary_path);
|
||||||
return false;
|
setup_succeed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transliteration_path != NULL) {
|
if (transliteration_path != NULL) {
|
||||||
@@ -289,7 +291,7 @@ bool libpostal_setup_datadir(char *datadir) {
|
|||||||
free(address_dictionary_path);
|
free(address_dictionary_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return setup_succeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool libpostal_setup(void) {
|
bool libpostal_setup(void) {
|
||||||
|
|||||||
Reference in New Issue
Block a user