]> granicus.if.org Git - p11-kit/commitdiff
Fix leak when C_Initialize() is called from child
authorDaiki Ueno <dueno@redhat.com>
Fri, 12 Aug 2016 14:16:38 +0000 (16:16 +0200)
committerStef Walter <stefw@redhat.com>
Mon, 22 Aug 2016 09:57:00 +0000 (11:57 +0200)
The test case added for bug 90289 (commit c73edd00) revealed that some
of the C_Initialize() implementations do not consider the case where it
is called from the parent process and then from the child process,
without calling C_Finalize() in between.

common/mock.c
p11-kit/modules.c

index 1b0aea791d21f3936ecd40d01b0abb1789055085..c3f25034dfa6134b633f8f29cd2dde5067311ffb 100644 (file)
@@ -422,9 +422,12 @@ mock_C_Initialize (CK_VOID_PTR init_args)
                /* We store CK_ULONG as pointers here, so verify that they fit */
                assert (sizeof (CK_ULONG) <= sizeof (void *));
 
+               free (the_pin);
                the_pin = (CK_UTF8CHAR_PTR)strdup ("booo");
                n_the_pin = 4;
 
+               if (the_sessions)
+                       p11_dict_free (the_sessions);
                the_sessions = p11_dict_new (p11_dict_direct_hash,
                                             p11_dict_direct_equal,
                                             NULL, free_session);
index f52c6e15afc7201fdb851892f2037a69f9bb0e84..1ec0f1da804ae0931fc21b5f031b5436412f27a1 100644 (file)
@@ -1480,6 +1480,8 @@ managed_C_Initialize (CK_X_FUNCTION_LIST *self,
                else
                        rv = initialize_module_inlock_reentrant (managed->mod);
                if (rv == CKR_OK) {
+                       if (managed->sessions)
+                               p11_dict_free (managed->sessions);
                        managed->sessions = sessions;
                        managed->initialized = p11_forkid;
                } else {