Skip to content

Commit 72cf28f

Browse files
committed
Fixed issues found by Coverity
The resource leak was real, if unlikely. I don't believe the NULL issues in from_map and from_array actually exist. I think the NULL checker thinks there may be an issue because of the NULL check in the for loop. However, I moved a null check from the Reader_get function to the from_entry_data_list function. If entry_data_list is NULL or the pointer that it points to is NULL, it will now be caught there before the from_map and from_array calls.
1 parent 277a538 commit 72cf28f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

maxminddb/extension/maxminddb.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static int Reader_init(PyObject *self, PyObject *args, PyObject *UNUSED(kwds))
7272

7373
Reader_obj *mmdb_obj = (Reader_obj *)self;
7474
if (!mmdb_obj) {
75+
free(mmdb);
7576
PyErr_NoMemory();
7677
return -1;
7778
}
@@ -146,12 +147,6 @@ static PyObject *Reader_get(PyObject *self, PyObject *args)
146147
ip_address, MMDB_strerror(status));
147148
MMDB_free_entry_data_list(entry_data_list);
148149
return NULL;
149-
} else if (NULL == entry_data_list) {
150-
PyErr_Format(
151-
MaxMindDB_error,
152-
"Error while looking up data for %s. Your database may be corrupt or you have found a bug in libmaxminddb.",
153-
ip_address);
154-
return NULL;
155150
}
156151

157152
MMDB_entry_data_list_s *original_entry_data_list = entry_data_list;
@@ -300,6 +295,14 @@ static void Metadata_dealloc(PyObject *self)
300295

301296
static PyObject *from_entry_data_list(MMDB_entry_data_list_s **entry_data_list)
302297
{
298+
if (NULL == entry_data_list || NULL == *entry_data_list) {
299+
PyErr_Format(
300+
MaxMindDB_error,
301+
"Error while looking up data. Your database may be corrupt or you have found a bug in libmaxminddb."
302+
);
303+
return NULL;
304+
}
305+
303306
switch ((*entry_data_list)->entry_data.type) {
304307
case MMDB_DATA_TYPE_MAP:
305308
return from_map(entry_data_list);

0 commit comments

Comments
 (0)