[Freeipa-devel] [PATCHES] 366-372 Additional Coverity fixes
Alexander Bokovoy
abokovoy at redhat.com
Tue Nov 25 08:18:40 UTC 2014
On Tue, 11 Nov 2014, Jan Cholasta wrote:
>>From 10b309f53852665050465df8aa44290dfe232291 Mon Sep 17 00:00:00 2001
>From: Jan Cholasta <jcholast at redhat.com>
>Date: Mon, 10 Nov 2014 17:33:23 +0000
>Subject: [PATCH 2/7] Unload P11_Helper object's library when it is finalized
> in ipap11helper
>
>https://fedorahosted.org/freeipa/ticket/4713
>---
> ipapython/ipap11helper/library.c | 5 +++++
> ipapython/ipap11helper/p11helper.c | 9 +++++++--
> 2 files changed, 12 insertions(+), 2 deletions(-)
>
>diff --git a/ipapython/ipap11helper/library.c b/ipapython/ipap11helper/library.c
>index 51e24eb..619604d 100644
>--- a/ipapython/ipap11helper/library.c
>+++ b/ipapython/ipap11helper/library.c
>@@ -70,6 +70,11 @@ CK_C_GetFunctionList loadLibrary(char* module, void** moduleHandle)
>
> // Retrieve the entry point for C_GetFunctionList
> pGetFunctionList = (CK_C_GetFunctionList) dlsym(pDynLib, "C_GetFunctionList");
>+ if (pGetFunctionList == NULL)
>+ {
>+ dlclose(pDynLib);
>+ return NULL;
>+ }
>
> // Store the handle so we can dlclose it later
> *moduleHandle = pDynLib;
>diff --git a/ipapython/ipap11helper/p11helper.c b/ipapython/ipap11helper/p11helper.c
>index 038c26c..558185e 100644
>--- a/ipapython/ipap11helper/p11helper.c
>+++ b/ipapython/ipap11helper/p11helper.c
>@@ -66,6 +66,7 @@ PyObject_HEAD
> CK_SLOT_ID slot;
> CK_FUNCTION_LIST_PTR p11;
> CK_SESSION_HANDLE session;
>+void *module_handle;
> } P11_Helper;
>
> typedef enum {
>@@ -478,6 +479,7 @@ P11_Helper_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
> self->slot = 0;
> self->session = 0;
> self->p11 = NULL;
>+ self->module_handle = NULL;
> }
>
> return (PyObject *) self;
>@@ -496,12 +498,12 @@ static int P11_Helper_init(P11_Helper *self, PyObject *args, PyObject *kwds) {
> CK_C_GetFunctionList pGetFunctionList = loadLibrary(library_path,
> &module_handle);
> if (!pGetFunctionList) {
>- if (module_handle != NULL)
>- unloadLibrary(module_handle);
> PyErr_SetString(ipap11helperError, "Could not load the library.");
> return -1;
> }
>
>+ self->module_handle = module_handle;
>+
> /*
> * Load the function list
> */
>@@ -567,9 +569,12 @@ P11_Helper_finalize(P11_Helper* self) {
> */
> self->p11->C_Finalize(NULL);
>
>+ unloadLibrary(self->module_handle);
>+
> self->p11 = NULL;
> self->session = 0;
> self->slot = 0;
>+ self->module_handle = NULL;
>
> return Py_None;
> }
ACK.
--
/ Alexander Bokovoy
More information about the Freeipa-devel
mailing list