summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Reichl <preichl@redhat.com>2014-09-29 16:40:53 +0100
committerJakub Hrozek <jhrozek@redhat.com>2014-10-22 16:40:25 +0200
commitc52d7c41e4127a84f487777c0efa6996f6389c51 (patch)
tree3ce123cc2fbe4e9a4cb0e643993f1e3af667e5d4
parentd3e69c059cb11c735d115a3914dad46806ff46fb (diff)
downloadsssd-c52d7c41e4127a84f487777c0efa6996f6389c51.tar.gz
sssd-c52d7c41e4127a84f487777c0efa6996f6389c51.tar.xz
sssd-c52d7c41e4127a84f487777c0efa6996f6389c51.zip
pyhbac,pysss: fix reference leaks
Resolves: https://fedorahosted.org/sssd/ticket/1195 Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
-rw-r--r--src/python/pyhbac.c22
-rw-r--r--src/python/pysss.c10
2 files changed, 20 insertions, 12 deletions
diff --git a/src/python/pyhbac.c b/src/python/pyhbac.c
index e9dce9b01..dd345a6eb 100644
--- a/src/python/pyhbac.c
+++ b/src/python/pyhbac.c
@@ -139,14 +139,17 @@ sequence_as_string_list(PyObject *seq, const char *paramname)
utf_item = get_utf8_string(item, p);
if (utf_item == NULL) {
+ Py_DECREF(item);
return NULL;
}
ret[i] = py_strdup(PyString_AsString(utf_item));
Py_DECREF(utf_item);
if (!ret[i]) {
+ Py_DECREF(item);
return NULL;
}
+ Py_DECREF(item);
}
ret[i] = NULL;
@@ -242,10 +245,7 @@ str_concat_sequence(PyObject *seq, const char *delim)
if (item == NULL) goto fail;
part = PyString_AsString(item);
- if (part == NULL) {
- Py_DECREF(item);
- goto fail;
- }
+ if (part == NULL) goto fail;
if (s) {
s = py_strcat_realloc(s, delim);
@@ -260,7 +260,9 @@ str_concat_sequence(PyObject *seq, const char *delim)
}
return s;
+
fail:
+ Py_XDECREF(item);
PyMem_Free(s);
return NULL;
}
@@ -269,11 +271,13 @@ fail:
static void
set_hbac_exception(PyObject *exc, struct hbac_info *error)
{
- PyErr_SetObject(exc,
- Py_BuildValue(sss_py_const_p(char, "(i,s)"),
- error->code,
- error->rule_name ? \
- error->rule_name : "no rule"));
+ PyObject *obj;
+
+ obj = Py_BuildValue(sss_py_const_p(char, "(i,s)"), error->code,
+ error->rule_name ? error->rule_name : "no rule");
+
+ PyErr_SetObject(exc, obj);
+ Py_XDECREF(obj);
}
/* ==================== HBAC Rule Element ========================*/
diff --git a/src/python/pysss.c b/src/python/pysss.c
index 8f98f081c..9e899f139 100644
--- a/src/python/pysss.c
+++ b/src/python/pysss.c
@@ -850,7 +850,7 @@ static PyObject *PySssLocalObject_new(PyTypeObject *type,
if (confdb_path == NULL) {
talloc_free(mem_ctx);
PyErr_NoMemory();
- return NULL;
+ goto fail;
}
/* Connect to the conf db */
@@ -859,7 +859,7 @@ static PyObject *PySssLocalObject_new(PyTypeObject *type,
talloc_free(mem_ctx);
PyErr_SetSssErrorWithMessage(ret,
"Could not initialize connection to the confdb\n");
- return NULL;
+ goto fail;
}
ret = sssd_domain_init(self->mem_ctx, self->confdb, "local",
@@ -868,7 +868,7 @@ static PyObject *PySssLocalObject_new(PyTypeObject *type,
talloc_free(mem_ctx);
PyErr_SetSssErrorWithMessage(ret,
"Could not initialize connection to the sysdb\n");
- return NULL;
+ goto fail;
}
self->sysdb = self->local->sysdb;
@@ -876,6 +876,10 @@ static PyObject *PySssLocalObject_new(PyTypeObject *type,
self->unlock = DO_UNLOCK;
return (PyObject *) self;
+
+fail:
+ Py_DECREF(self);
+ return NULL;
}
/*