pyldb: Properly preallocate result control list
authorPetr Viktorin <pviktori@redhat.com>
Tue, 3 Mar 2015 21:29:08 +0000 (22:29 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 3 Mar 2015 22:20:06 +0000 (23:20 +0100)
The list was always allocated with size 1, so
if there is more than 1 result control, the additional
items would not be added in the list, and would
become leaked references.

Signed-off-by: Petr Viktorin <pviktori@redhat.com>
Reviewed-by: Jelmer Vernooij <jelmer@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/pyldb.c

index 4f452fa5e758bb96379cf311966b7033160d19d0..9ee71eb73fa68a78a6ee27abcaeaf0e05adedc0b 100644 (file)
@@ -269,7 +269,11 @@ static PyObject *PyLdbResult_FromResult(struct ldb_result *result)
        ret->msgs = list;
 
        if (result->controls) {
-               controls = PyList_New(1);
+               i = 0;
+               while (result->controls[i]) {
+                       i++;
+               }
+               controls = PyList_New(i);
                if (controls == NULL) {
                        Py_DECREF(ret);
                        PyErr_NoMemory();