Skip to content

Commit 83832e1

Browse files
committed
Correct reference accounting for "bytes"
1 parent 4bd9b2f commit 83832e1

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

extension/maxminddb.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,14 @@ static PyObject *Reader_get(PyObject *self, PyObject *args)
182182
MMDB_lookup_string(mmdb, ip_address, &gai_error,
183183
&mmdb_error);
184184

185-
#if PY_MAJOR_VERSION >= 3
186-
if (bytes != NULL) {
187-
Py_DECREF(bytes);
188-
}
189-
#endif
190-
191185
if (0 != gai_error) {
192186
PyErr_Format(PyExc_ValueError,
193187
"'%s' does not appear to be an IPv4 or IPv6 address.",
194188
ip_address);
189+
190+
#if PY_MAJOR_VERSION >= 3
191+
Py_XDECREF(bytes);
192+
#endif
195193
return NULL;
196194
}
197195

@@ -204,6 +202,9 @@ static PyObject *Reader_get(PyObject *self, PyObject *args)
204202
}
205203
PyErr_Format(exception, "Error looking up %s. %s",
206204
ip_address, MMDB_strerror(mmdb_error));
205+
#if PY_MAJOR_VERSION >= 3
206+
Py_XDECREF(bytes);
207+
#endif
207208
return NULL;
208209
}
209210

@@ -218,9 +219,16 @@ static PyObject *Reader_get(PyObject *self, PyObject *args)
218219
"Error while looking up data for %s. %s",
219220
ip_address, MMDB_strerror(status));
220221
MMDB_free_entry_data_list(entry_data_list);
222+
#if PY_MAJOR_VERSION >= 3
223+
Py_XDECREF(bytes);
224+
#endif
221225
return NULL;
222226
}
223227

228+
#if PY_MAJOR_VERSION >= 3
229+
Py_XDECREF(bytes);
230+
#endif
231+
224232
MMDB_entry_data_list_s *original_entry_data_list = entry_data_list;
225233
PyObject *py_obj = from_entry_data_list(&entry_data_list);
226234
MMDB_free_entry_data_list(original_entry_data_list);

0 commit comments

Comments
 (0)