Merge pull request #297 from oschwald/greg/fix-more-leaks
Fix several more memory leaks and a segfault
This commit is contained in:
@@ -1755,8 +1755,6 @@ libpostal_address_parser_response_t *address_parser_parse(char *address, char *l
|
|||||||
label = strdup(ADDRESS_PARSER_LABEL_POSTAL_CODE);
|
label = strdup(ADDRESS_PARSER_LABEL_POSTAL_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
response = address_parser_response_new();
|
|
||||||
|
|
||||||
// Implicit: if most_common is not one of the above, ignore and parse regularly
|
// Implicit: if most_common is not one of the above, ignore and parse regularly
|
||||||
if (label != NULL) {
|
if (label != NULL) {
|
||||||
char **single_label = malloc(sizeof(char *));
|
char **single_label = malloc(sizeof(char *));
|
||||||
@@ -1764,6 +1762,8 @@ libpostal_address_parser_response_t *address_parser_parse(char *address, char *l
|
|||||||
char **single_component = malloc(sizeof(char *));
|
char **single_component = malloc(sizeof(char *));
|
||||||
single_component[0] = strdup(normalized);
|
single_component[0] = strdup(normalized);
|
||||||
|
|
||||||
|
response = address_parser_response_new();
|
||||||
|
|
||||||
response->num_components = 1;
|
response->num_components = 1;
|
||||||
response->labels = single_label;
|
response->labels = single_label;
|
||||||
response->components = single_component;
|
response->components = single_component;
|
||||||
|
|||||||
@@ -1491,8 +1491,12 @@ void expand_alternative_phrase_option(cstring_array *strings, khash_t(str_set) *
|
|||||||
for (; !string_tree_iterator_done(iter); string_tree_iterator_next(iter)) {
|
for (; !string_tree_iterator_done(iter); string_tree_iterator_next(iter)) {
|
||||||
char_array_clear(temp_string);
|
char_array_clear(temp_string);
|
||||||
string_tree_iterator_foreach_token(iter, token, {
|
string_tree_iterator_foreach_token(iter, token, {
|
||||||
log_debug("token=%s\n", token);
|
if (token == NULL) {
|
||||||
char_array_append(temp_string, token);
|
log_debug("token=NULL\n");
|
||||||
|
} else {
|
||||||
|
log_debug("token=%s\n", token);
|
||||||
|
char_array_append(temp_string, token);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
char_array_terminate(temp_string);
|
char_array_terminate(temp_string);
|
||||||
|
|
||||||
|
|||||||
@@ -1232,6 +1232,7 @@ char *replace_numeric_expressions(char *str, char *lang) {
|
|||||||
|
|
||||||
if (!have_valid_numex) {
|
if (!have_valid_numex) {
|
||||||
numex_result_array_destroy(results);
|
numex_result_array_destroy(results);
|
||||||
|
char_array_destroy(replacement);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,15 @@ TEST test_expansions(void) {
|
|||||||
CHECK_CALL(test_expansion_contains_with_languages("Marktstrasse", "markt strasse", options, 1, "de"));
|
CHECK_CALL(test_expansion_contains_with_languages("Marktstrasse", "markt strasse", options, 1, "de"));
|
||||||
CHECK_CALL(test_expansion_contains_with_languages("Hoofdstraat", "hoofdstraat", options, 1, "nl"));
|
CHECK_CALL(test_expansion_contains_with_languages("Hoofdstraat", "hoofdstraat", options, 1, "nl"));
|
||||||
CHECK_CALL(test_expansion_contains_with_languages("มงแตร", "มงแตร", options, 1, "th"));
|
CHECK_CALL(test_expansion_contains_with_languages("มงแตร", "มงแตร", options, 1, "th"));
|
||||||
|
|
||||||
|
PASS();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST test_expansion_for_invalid_input(void) {
|
||||||
|
size_t num_expansions;
|
||||||
|
|
||||||
|
// This is tested as the input caused a segfault in expand_alternative_phrase_option
|
||||||
|
libpostal_expand_address("bob-ad1233@blah.co", libpostal_get_default_options(), &num_expansions);
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,6 +323,7 @@ SUITE(libpostal_expansion_tests) {
|
|||||||
RUN_TEST(test_po_box_root_expansions);
|
RUN_TEST(test_po_box_root_expansions);
|
||||||
RUN_TEST(test_expansions_language_classifier);
|
RUN_TEST(test_expansions_language_classifier);
|
||||||
RUN_TEST(test_expansions_no_options);
|
RUN_TEST(test_expansions_no_options);
|
||||||
|
RUN_TEST(test_expansion_for_invalid_input);
|
||||||
|
|
||||||
libpostal_teardown();
|
libpostal_teardown();
|
||||||
libpostal_teardown_language_classifier();
|
libpostal_teardown_language_classifier();
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ TEST test_trie(void) {
|
|||||||
ASSERT(phrase.start == 2);
|
ASSERT(phrase.start == 2);
|
||||||
ASSERT(phrase.len == 1);
|
ASSERT(phrase.len == 1);
|
||||||
|
|
||||||
|
phrase_array_destroy(phrases);
|
||||||
|
token_array_destroy(tokens);
|
||||||
trie_destroy(trie);
|
trie_destroy(trie);
|
||||||
|
|
||||||
PASS();
|
PASS();
|
||||||
|
|||||||
Reference in New Issue
Block a user