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