[PATCH 11/14] pytdb: Check errors after PyObject_New() calls
Kirill Smelkov
kirr at landau.phys.spbu.ru
Sat Oct 2 07:43:50 MDT 2010
The call could fail with e.g. MemoryError, and we'll dereference NULL
pointer without checking.
Signed-off-by: Kirill Smelkov <kirr at landau.phys.spbu.ru>
---
lib/tdb/pytdb.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/lib/tdb/pytdb.c b/lib/tdb/pytdb.c
index f119f5e..713b026 100644
--- a/lib/tdb/pytdb.c
+++ b/lib/tdb/pytdb.c
@@ -122,6 +122,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;
@@ -424,6 +429,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);
--
1.7.3.1.50.g1e633
More information about the samba-technical
mailing list