Skip to content

Commit 75d485e

Browse files
committed
PYTHON-2680 Fix C DBRef hook, return new dbref object without decref
1 parent 54944c0 commit 75d485e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

bson/_cbsonmodule.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ static PyObject* _cbson_dict_to_bson(PyObject* self, PyObject* args) {
15091509
/*
15101510
* Hook for optional decoding BSON documents to DBRef.
15111511
*/
1512-
static PyObject *_decode_as_dbref(PyObject* self, PyObject* value) {
1512+
static PyObject *_dbref_hook(PyObject* self, PyObject* value) {
15131513
struct module_state *state = GETSTATE(self);
15141514
PyObject* dbref = NULL;
15151515
PyObject* dbref_type = NULL;
@@ -1558,13 +1558,12 @@ static PyObject *_decode_as_dbref(PyObject* self, PyObject* value) {
15581558
if ((dbref_type = _get_object(state->DBRef, "bson.dbref", "DBRef"))) {
15591559
dbref = PyObject_CallFunctionObjArgs(dbref_type, ref, id, database, value, NULL);
15601560
Py_DECREF(value);
1561-
value = dbref;
1561+
ret = dbref;
15621562
}
15631563
} else {
15641564
ret = value;
15651565
}
15661566
invalid:
1567-
Py_XDECREF(dbref);
15681567
Py_XDECREF(dbref_type);
15691568
Py_XDECREF(ref);
15701569
Py_XDECREF(id);
@@ -1651,7 +1650,7 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer,
16511650
}
16521651

16531652
/* Hook for DBRefs */
1654-
value = _decode_as_dbref(self, value);
1653+
value = _dbref_hook(self, value);
16551654
if (!value) {
16561655
goto invalid;
16571656
}

0 commit comments

Comments
 (0)