libselinux: audit2why: Fix segfault if finish() called twice

If audit2why.finish is called more than once the global avc variable
will be NULL, and thus dereferencing it will obviously cause problems.
Thus just bail if avc is NULL and we know cleanup is done.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
rhatdan 2012-10-15 15:25:31 -04:00 committed by Eric Paris
parent 2677b72191
commit 019e6fd6d4

View file

@ -164,6 +164,9 @@ static PyObject *finish(PyObject *self __attribute__((unused)), PyObject *args)
if (PyArg_ParseTuple(args,(char *)":finish")) {
int i = 0;
if (! avc)
Py_RETURN_NONE;
for (i = 0; i < boolcnt; i++) {
free(boollist[i]->name);
free(boollist[i]);
@ -177,7 +180,7 @@ static PyObject *finish(PyObject *self __attribute__((unused)), PyObject *args)
avc = NULL;
boollist = NULL;
boolcnt = 0;
/* Boilerplate to return "None" */
Py_RETURN_NONE;
}