summaryrefslogtreecommitdiff
path: root/p11-kit
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2016-09-22 09:16:48 +0200
committerDaiki Ueno <ueno@gnu.org>2016-10-31 12:59:17 +0100
commitecaf79c6a0b35e55b27f465c6d6628f165874b78 (patch)
treef494d2515d0b4ba2b5ff230adc87aaa0806482bf /p11-kit
parentae0527969dbb2dea5bf97257c92a65b72ba71db5 (diff)
modules: Reset the init count on fork()
Reset mod->init_count when forkid has changed. Otherwise C_Finalize does not get called. GCC's asan spotted this: Direct leak of 48 byte(s) in 1 object(s) allocated from: #0 0x7f89bc7bfe20 in malloc (/lib64/libasan.so.3+0xc6e20) #1 0x7f89bc47a1f1 in p11_dict_new ../common/dict.c:278 #2 0x7f89bc42143d in managed_C_Initialize ../p11-kit/modules.c:1477 #3 0x7f89bc464c72 in binding_C_Initialize ../p11-kit/virtual.c:121 #4 0x7f89bc1b0a51 in ffi_closure_unix64_inner (/lib64/libffi.so.6+0x5a51) #5 0x7f89bc1b0dbf in ffi_closure_unix64 (/lib64/libffi.so.6+0x5dbf) #6 0x7f89bc44f9e8 in rpc_C_Initialize ../p11-kit/rpc-server.c:691
Diffstat (limited to 'p11-kit')
-rw-r--r--p11-kit/modules.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/p11-kit/modules.c b/p11-kit/modules.c
index 4af2a83..fc456ce 100644
--- a/p11-kit/modules.c
+++ b/p11-kit/modules.c
@@ -658,6 +658,10 @@ initialize_module_inlock_reentrant (Module *mod, CK_C_INITIALIZE_ARGS *init_args
/* Module was already initialized, we don't call C_Finalize */
if (rv == CKR_CRYPTOKI_ALREADY_INITIALIZED)
rv = CKR_OK;
+
+ /* Matches the init count in finalize_module_inlock_reentrant() */
+ if (rv == CKR_OK)
+ mod->init_count = 0;
}
p11_mutex_unlock (&mod->initialize_mutex);