Skip to content

Commit 77e547e

Browse files
committed
fix: memory leak in MMDB_open()
Signed-off-by: Arjun <[email protected]>
1 parent 0fd8898 commit 77e547e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/maxminddb.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,19 +744,22 @@ static int populate_languages_metadata(MMDB_s *mmdb,
744744
mmdb->metadata.languages.count = 0;
745745
mmdb->metadata.languages.names = calloc(array_size, sizeof(char *));
746746
if (NULL == mmdb->metadata.languages.names) {
747+
MMDB_free_entry_data_list(first_member);
747748
return MMDB_OUT_OF_MEMORY_ERROR;
748749
}
749750

750751
for (uint32_t i = 0; i < array_size; i++) {
751752
member = member->next;
752753
if (MMDB_DATA_TYPE_UTF8_STRING != member->entry_data.type) {
754+
MMDB_free_entry_data_list(first_member);
753755
return MMDB_INVALID_METADATA_ERROR;
754756
}
755757

756758
mmdb->metadata.languages.names[i] = mmdb_strndup(
757759
member->entry_data.utf8_string, member->entry_data.data_size);
758760

759761
if (NULL == mmdb->metadata.languages.names[i]) {
762+
MMDB_free_entry_data_list(first_member);
760763
return MMDB_OUT_OF_MEMORY_ERROR;
761764
}
762765
// We assign this as we go so that if we fail a calloc and need to
@@ -1646,6 +1649,10 @@ int MMDB_get_entry_data_list(MMDB_entry_s *start,
16461649

16471650
int const status =
16481651
get_entry_data_list(start->mmdb, start->offset, list, pool, 0);
1652+
if (MMDB_SUCCESS != status) {
1653+
data_pool_destroy(pool);
1654+
return status;
1655+
}
16491656

16501657
*entry_data_list = data_pool_to_list(pool);
16511658
if (!*entry_data_list) {

0 commit comments

Comments
 (0)