|
|
905b4d |
From b615258d6df8ad867cee99bdccffff05127fbc92 Mon Sep 17 00:00:00 2001
|
|
|
905b4d |
From: Pavel Reichl <preichl@redhat.com>
|
|
|
905b4d |
Date: Mon, 29 Sep 2014 16:40:53 +0100
|
|
|
905b4d |
Subject: [PATCH 22/22] pyhbac,pysss: fix reference leaks
|
|
|
905b4d |
|
|
|
905b4d |
Resolves:
|
|
|
905b4d |
https://fedorahosted.org/sssd/ticket/1195
|
|
|
905b4d |
|
|
|
905b4d |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
905b4d |
---
|
|
|
905b4d |
src/python/pyhbac.c | 22 +++++++++++++---------
|
|
|
905b4d |
src/python/pysss.c | 10 +++++++---
|
|
|
905b4d |
2 files changed, 20 insertions(+), 12 deletions(-)
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/src/python/pyhbac.c b/src/python/pyhbac.c
|
|
|
905b4d |
index e9dce9b01b78401516b5c21141be8007b4a94aec..dd345a6eb4db8ac6104251d5b9c8f11a160e280d 100644
|
|
|
905b4d |
--- a/src/python/pyhbac.c
|
|
|
905b4d |
+++ b/src/python/pyhbac.c
|
|
|
905b4d |
@@ -139,14 +139,17 @@ sequence_as_string_list(PyObject *seq, const char *paramname)
|
|
|
905b4d |
|
|
|
905b4d |
utf_item = get_utf8_string(item, p);
|
|
|
905b4d |
if (utf_item == NULL) {
|
|
|
905b4d |
+ Py_DECREF(item);
|
|
|
905b4d |
return NULL;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
ret[i] = py_strdup(PyString_AsString(utf_item));
|
|
|
905b4d |
Py_DECREF(utf_item);
|
|
|
905b4d |
if (!ret[i]) {
|
|
|
905b4d |
+ Py_DECREF(item);
|
|
|
905b4d |
return NULL;
|
|
|
905b4d |
}
|
|
|
905b4d |
+ Py_DECREF(item);
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
ret[i] = NULL;
|
|
|
905b4d |
@@ -242,10 +245,7 @@ str_concat_sequence(PyObject *seq, const char *delim)
|
|
|
905b4d |
if (item == NULL) goto fail;
|
|
|
905b4d |
|
|
|
905b4d |
part = PyString_AsString(item);
|
|
|
905b4d |
- if (part == NULL) {
|
|
|
905b4d |
- Py_DECREF(item);
|
|
|
905b4d |
- goto fail;
|
|
|
905b4d |
- }
|
|
|
905b4d |
+ if (part == NULL) goto fail;
|
|
|
905b4d |
|
|
|
905b4d |
if (s) {
|
|
|
905b4d |
s = py_strcat_realloc(s, delim);
|
|
|
905b4d |
@@ -260,7 +260,9 @@ str_concat_sequence(PyObject *seq, const char *delim)
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
return s;
|
|
|
905b4d |
+
|
|
|
905b4d |
fail:
|
|
|
905b4d |
+ Py_XDECREF(item);
|
|
|
905b4d |
PyMem_Free(s);
|
|
|
905b4d |
return NULL;
|
|
|
905b4d |
}
|
|
|
905b4d |
@@ -269,11 +271,13 @@ fail:
|
|
|
905b4d |
static void
|
|
|
905b4d |
set_hbac_exception(PyObject *exc, struct hbac_info *error)
|
|
|
905b4d |
{
|
|
|
905b4d |
- PyErr_SetObject(exc,
|
|
|
905b4d |
- Py_BuildValue(sss_py_const_p(char, "(i,s)"),
|
|
|
905b4d |
- error->code,
|
|
|
905b4d |
- error->rule_name ? \
|
|
|
905b4d |
- error->rule_name : "no rule"));
|
|
|
905b4d |
+ PyObject *obj;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ obj = Py_BuildValue(sss_py_const_p(char, "(i,s)"), error->code,
|
|
|
905b4d |
+ error->rule_name ? error->rule_name : "no rule");
|
|
|
905b4d |
+
|
|
|
905b4d |
+ PyErr_SetObject(exc, obj);
|
|
|
905b4d |
+ Py_XDECREF(obj);
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
/* ==================== HBAC Rule Element ========================*/
|
|
|
905b4d |
diff --git a/src/python/pysss.c b/src/python/pysss.c
|
|
|
905b4d |
index 8f98f081c9600b74f5953faef40cb40b30388319..9e899f1399553a950e41e157612a7360de4c07b5 100644
|
|
|
905b4d |
--- a/src/python/pysss.c
|
|
|
905b4d |
+++ b/src/python/pysss.c
|
|
|
905b4d |
@@ -850,7 +850,7 @@ static PyObject *PySssLocalObject_new(PyTypeObject *type,
|
|
|
905b4d |
if (confdb_path == NULL) {
|
|
|
905b4d |
talloc_free(mem_ctx);
|
|
|
905b4d |
PyErr_NoMemory();
|
|
|
905b4d |
- return NULL;
|
|
|
905b4d |
+ goto fail;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
/* Connect to the conf db */
|
|
|
905b4d |
@@ -859,7 +859,7 @@ static PyObject *PySssLocalObject_new(PyTypeObject *type,
|
|
|
905b4d |
talloc_free(mem_ctx);
|
|
|
905b4d |
PyErr_SetSssErrorWithMessage(ret,
|
|
|
905b4d |
"Could not initialize connection to the confdb\n");
|
|
|
905b4d |
- return NULL;
|
|
|
905b4d |
+ goto fail;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
ret = sssd_domain_init(self->mem_ctx, self->confdb, "local",
|
|
|
905b4d |
@@ -868,7 +868,7 @@ static PyObject *PySssLocalObject_new(PyTypeObject *type,
|
|
|
905b4d |
talloc_free(mem_ctx);
|
|
|
905b4d |
PyErr_SetSssErrorWithMessage(ret,
|
|
|
905b4d |
"Could not initialize connection to the sysdb\n");
|
|
|
905b4d |
- return NULL;
|
|
|
905b4d |
+ goto fail;
|
|
|
905b4d |
}
|
|
|
905b4d |
self->sysdb = self->local->sysdb;
|
|
|
905b4d |
|
|
|
905b4d |
@@ -876,6 +876,10 @@ static PyObject *PySssLocalObject_new(PyTypeObject *type,
|
|
|
905b4d |
self->unlock = DO_UNLOCK;
|
|
|
905b4d |
|
|
|
905b4d |
return (PyObject *) self;
|
|
|
905b4d |
+
|
|
|
905b4d |
+fail:
|
|
|
905b4d |
+ Py_DECREF(self);
|
|
|
905b4d |
+ return NULL;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
/*
|
|
|
905b4d |
--
|
|
|
905b4d |
1.9.3
|
|
|
905b4d |
|