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>
This commit is contained in:
Jan Cholasta
2014-11-25 08:23:24 +00:00
parent 313da898bb
commit 968e1bbcf8
2 changed files with 12 additions and 2 deletions
+5
View File
@@ -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;
+7 -2
View File
@@ -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;
}