Skip to content

Commit 2a4eb44

Browse files
authored
Merge pull request #52 from maxmind/greg/fix-segfault
Fix segfault due to incorrect reference counting
2 parents 58db073 + a5c9585 commit 2a4eb44

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

HISTORY.rst

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
History
44
-------
55

6+
1.5.1 (2019-09-27)
7+
++++++++++++++++++
8+
9+
* Fix a possible segfault due to not correctly incrementing the reference
10+
on a returned object.
11+
612
1.5.0 (2019-09-27)
713
++++++++++++++++++
814

extension/maxminddb.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ static PyObject *Reader_get_with_prefix_len(PyObject *self, PyObject *args) {
127127
return NULL;
128128
}
129129

130-
return PyTuple_Pack(2, record, PyLong_FromLong(prefix_len));
130+
PyObject *tuple = Py_BuildValue("(Oi)", record, prefix_len);
131+
Py_DECREF(record);
132+
133+
return tuple;
131134
}
132135

133136
static int get_record(PyObject *self, PyObject *args, PyObject **record) {
@@ -178,6 +181,7 @@ static int get_record(PyObject *self, PyObject *args, PyObject **record) {
178181
}
179182

180183
if (!result.found_entry) {
184+
Py_INCREF(Py_None);
181185
*record = Py_None;
182186
return prefix_len;
183187
}

0 commit comments

Comments
 (0)