The parse_ldif and MessageElement.__iter__ functions leaked references
to intermediate lists whose iterators they return.
The MessageElement repr used the undocumented macro PyObject_REPR, which
leaks references. (It was used internally in CPython before fatal errors,
and will be removed in Python 3.5.)
Signed-off-by: Petr Viktorin <pviktori@redhat.com>
Reviewed-by: Jelmer Vernooij <jelmer@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args)
{
static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args)
{
struct ldb_ldif *ldif;
const char *s;
struct ldb_ldif *ldif;
const char *s;
}
}
talloc_free(mem_ctx); /* The pyobject already has a reference to the things it needs */
}
}
talloc_free(mem_ctx); /* The pyobject already has a reference to the things it needs */
- return PyObject_GetIter(list);
+ ret = PyObject_GetIter(list);
+ Py_DECREF(list);
+ return ret;
}
static PyObject *py_ldb_msg_diff(PyLdbObject *self, PyObject *args)
}
static PyObject *py_ldb_msg_diff(PyLdbObject *self, PyObject *args)
{
PyObject *el = ldb_msg_element_to_set(NULL,
pyldb_MessageElement_AsMessageElement(self));
{
PyObject *el = ldb_msg_element_to_set(NULL,
pyldb_MessageElement_AsMessageElement(self));
- return PyObject_GetIter(el);
+ PyObject *ret = PyObject_GetIter(el);
+ Py_DECREF(el);
+ return ret;
}
static PyObject *PyLdbMessageElement_FromMessageElement(struct ldb_message_element *el, TALLOC_CTX *mem_ctx)
}
static PyObject *PyLdbMessageElement_FromMessageElement(struct ldb_message_element *el, TALLOC_CTX *mem_ctx)
char *element_str = NULL;
Py_ssize_t i;
struct ldb_message_element *el = pyldb_MessageElement_AsMessageElement(self);
char *element_str = NULL;
Py_ssize_t i;
struct ldb_message_element *el = pyldb_MessageElement_AsMessageElement(self);
for (i = 0; i < el->num_values; i++) {
PyObject *o = py_ldb_msg_element_find(self, i);
for (i = 0; i < el->num_values; i++) {
PyObject *o = py_ldb_msg_element_find(self, i);
+ repr = PyObject_Repr(o);
- element_str = talloc_strdup(NULL, PyObject_REPR(o));
+ element_str = talloc_strdup(NULL, PyString_AsString(repr));
- element_str = talloc_asprintf_append(element_str, ",%s", PyObject_REPR(o));
+ element_str = talloc_asprintf_append(element_str, ",%s", PyString_AsString(repr));
+ Py_DECREF(repr);
}
if (element_str != NULL) {
}
if (element_str != NULL) {