diff --git a/HISTORY.rst b/HISTORY.rst index 97dbe22..6f4ee7f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,12 @@ History ------- +1.5.1 (2019-09-27) +++++++++++++++++++ + +* Fix a possible segfault due to not correctly incrementing the reference + on a returned object. + 1.5.0 (2019-09-27) ++++++++++++++++++ diff --git a/extension/maxminddb.c b/extension/maxminddb.c index f24095e..69f18c5 100644 --- a/extension/maxminddb.c +++ b/extension/maxminddb.c @@ -127,7 +127,10 @@ static PyObject *Reader_get_with_prefix_len(PyObject *self, PyObject *args) { return NULL; } - return PyTuple_Pack(2, record, PyLong_FromLong(prefix_len)); + PyObject *tuple = Py_BuildValue("(Oi)", record, prefix_len); + Py_DECREF(record); + + return tuple; } static int get_record(PyObject *self, PyObject *args, PyObject **record) { @@ -178,6 +181,7 @@ static int get_record(PyObject *self, PyObject *args, PyObject **record) { } if (!result.found_entry) { + Py_INCREF(Py_None); *record = Py_None; return prefix_len; }