pytdb: Check errors after PyObject_New() calls
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Sat, 2 Oct 2010 13:43:50 +0000 (17:43 +0400)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 7 Oct 2010 04:48:29 +0000 (15:18 +1030)
The call could fail with e.g. MemoryError, and we'll dereference NULL
pointer without checking.

Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
lib/tdb/pytdb.c

index 402fa5d9d3a0f674cb65ad6762b6661d3fd338c5..009063359f7b7f9f116a96fc33da5fe1401caf6b 100644 (file)
@@ -97,6 +97,11 @@ static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwarg
        }
 
        ret = PyObject_New(PyTdbObject, &PyTdb);
+       if (!ret) {
+               tdb_close(ctx);
+               return NULL;
+       }
+
        ret->ctx = ctx;
        ret->closed = false;
        return (PyObject *)ret;
@@ -330,6 +335,8 @@ static PyObject *tdb_object_iter(PyTdbObject *self)
        PyTdbIteratorObject *ret;       
 
        ret = PyObject_New(PyTdbIteratorObject, &PyTdbIterator);
+       if (!ret)
+               return NULL;
        ret->current = tdb_firstkey(self->ctx);
        ret->iteratee = self;
        Py_INCREF(self);