diff options
author | Jan Cholasta <jcholast@redhat.com> | 2014-11-10 17:33:23 +0000 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2014-11-25 08:23:24 +0000 |
commit | 968e1bbcf8f226e1abaa90df7cf31ae3143ade03 (patch) | |
tree | 1b5b8ba1e7f623d1a66127187e0cb2bbdf1f4281 /ipapython | |
parent | 313da898bb5e88ab6507322fae137af50b1b0f7e (diff) | |
download | freeipa-968e1bbcf8f226e1abaa90df7cf31ae3143ade03.tar.gz freeipa-968e1bbcf8f226e1abaa90df7cf31ae3143ade03.tar.xz freeipa-968e1bbcf8f226e1abaa90df7cf31ae3143ade03.zip |
Unload P11_Helper object's library when it is finalized in ipap11helper
https://fedorahosted.org/freeipa/ticket/4713
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
Diffstat (limited to 'ipapython')
-rw-r--r-- | ipapython/ipap11helper/library.c | 5 | ||||
-rw-r--r-- | 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 fc4c1e41c..acae47e5c 100644 --- a/ipapython/ipap11helper/library.c +++ b/ipapython/ipap11helper/library.c @@ -66,6 +66,11 @@ CK_C_GetFunctionList loadLibrary(const 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 c1d100772..c7c259590 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; } |