From 90459a564c11db21071167e5bc585d5adcec21aa Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Thu, 11 Oct 2012 09:42:51 -0700 Subject: [PATCH] Don't leak if decode_all fails. --- bson/_cbsonmodule.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c index d25a90890..1eb324db4 100644 --- a/bson/_cbsonmodule.c +++ b/bson/_cbsonmodule.c @@ -1765,6 +1765,7 @@ static PyObject* _cbson_decode_all(PyObject* self, PyObject* args) { PyErr_SetString(InvalidBSON, "not enough data for a BSON document"); Py_DECREF(InvalidBSON); + Py_DECREF(result); return NULL; } @@ -1775,6 +1776,7 @@ static PyObject* _cbson_decode_all(PyObject* self, PyObject* args) { PyErr_SetString(InvalidBSON, "objsize too large"); Py_DECREF(InvalidBSON); + Py_DECREF(result); return NULL; } @@ -1783,12 +1785,14 @@ static PyObject* _cbson_decode_all(PyObject* self, PyObject* args) { PyErr_SetString(InvalidBSON, "bad eoo"); Py_DECREF(InvalidBSON); + Py_DECREF(result); return NULL; } dict = elements_to_dict(self, string + 4, size - 5, as_class, tz_aware, uuid_subtype); if (!dict) { + Py_DECREF(result); return NULL; } PyList_Append(result, dict);