From 18cc0e37e644c85f2833c4be68d6107db310bdfb Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Tue, 2 Jan 2018 11:56:02 -0800 Subject: [PATCH] Only create parser response when it is used Previously, an unused response would not be freed, causing a leak. --- src/address_parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/address_parser.c b/src/address_parser.c index 9cfa17a6..2b7c8811 100644 --- a/src/address_parser.c +++ b/src/address_parser.c @@ -1755,8 +1755,6 @@ libpostal_address_parser_response_t *address_parser_parse(char *address, char *l 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 if (label != NULL) { 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 *)); single_component[0] = strdup(normalized); + response = address_parser_response_new(); + response->num_components = 1; response->labels = single_label; response->components = single_component;