From ecaf79c6a0b35e55b27f465c6d6628f165874b78 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Thu, 22 Sep 2016 09:16:48 +0200 Subject: 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 --- p11-kit/modules.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'p11-kit') 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); -- cgit v1.1