From 77e547eba23903663e9b07c496b6e5b850a54c3b Mon Sep 17 00:00:00 2001 From: Arjun Date: Tue, 5 Nov 2024 08:30:21 +0530 Subject: [PATCH 1/2] fix: memory leak in MMDB_open() Signed-off-by: Arjun --- src/maxminddb.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/maxminddb.c b/src/maxminddb.c index 55a3ce20..d458f727 100644 --- a/src/maxminddb.c +++ b/src/maxminddb.c @@ -744,12 +744,14 @@ static int populate_languages_metadata(MMDB_s *mmdb, mmdb->metadata.languages.count = 0; mmdb->metadata.languages.names = calloc(array_size, sizeof(char *)); if (NULL == mmdb->metadata.languages.names) { + MMDB_free_entry_data_list(first_member); return MMDB_OUT_OF_MEMORY_ERROR; } for (uint32_t i = 0; i < array_size; i++) { member = member->next; if (MMDB_DATA_TYPE_UTF8_STRING != member->entry_data.type) { + MMDB_free_entry_data_list(first_member); return MMDB_INVALID_METADATA_ERROR; } @@ -757,6 +759,7 @@ static int populate_languages_metadata(MMDB_s *mmdb, member->entry_data.utf8_string, member->entry_data.data_size); if (NULL == mmdb->metadata.languages.names[i]) { + MMDB_free_entry_data_list(first_member); return MMDB_OUT_OF_MEMORY_ERROR; } // 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, int const status = get_entry_data_list(start->mmdb, start->offset, list, pool, 0); + if (MMDB_SUCCESS != status) { + data_pool_destroy(pool); + return status; + } *entry_data_list = data_pool_to_list(pool); if (!*entry_data_list) { From 69af4e01a51da35530496e5fef718c817025b328 Mon Sep 17 00:00:00 2001 From: Arjun Date: Fri, 8 Nov 2024 10:53:46 +0530 Subject: [PATCH 2/2] Fix: double free in bad_pointers_t Signed-off-by: Arjun --- t/bad_pointers_t.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/t/bad_pointers_t.c b/t/bad_pointers_t.c index 9dd0cf81..9bf31fb1 100644 --- a/t/bad_pointers_t.c +++ b/t/bad_pointers_t.c @@ -28,8 +28,6 @@ void run_tests(int mode, const char *mode_desc) { MMDB_INVALID_DATA_ERROR, "MMDB_get_entry_data_list returns MMDB_INVALID_DATA_ERROR for " "bad pointer in data section"); - - MMDB_free_entry_data_list(entry_data_list); } {