pyldb: Fix memory leak of LdbMessage's created from Python.
authorJelmer Vernooij <jelmer@samba.org>
Wed, 17 Jun 2009 17:01:06 +0000 (19:01 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 17 Jun 2009 18:45:38 +0000 (20:45 +0200)
source4/lib/ldb/pyldb.c

index ce38e066384c15fbc63ff13eb2cdd4a9c13abd5d..8e7ba4df90765e2d485e82a0167f2511f249107f 100644 (file)
@@ -1677,18 +1677,22 @@ static PyObject *py_ldb_msg_new(PyTypeObject *type, PyObject *args, PyObject *kw
                return NULL;
        }
 
-       if (pydn != NULL)
-               if (!PyObject_AsDn(NULL, pydn, NULL, &ret->dn))
+       if (pydn != NULL) {
+               if (!PyObject_AsDn(NULL, pydn, NULL, &ret->dn)) {
+                       talloc_free(ret);
                        return NULL;
+               }
+       }
 
        py_ret = (PyLdbMessageObject *)type->tp_alloc(type, 0);
        if (py_ret == NULL) {
                PyErr_NoMemory();
+               talloc_free(ret);
                return NULL;
        }
 
        py_ret->mem_ctx = talloc_new(NULL);
-       py_ret->msg = talloc_reference(py_ret->mem_ctx, ret);
+       py_ret->msg = talloc_steal(py_ret->mem_ctx, ret);
        return (PyObject *)py_ret;
 }