From dce4b5551208a07831b3859b4265bf6b2c4eb041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Sun, 1 Oct 2006 18:05:05 +0000 Subject: [PATCH] Fix double free's, NULL ptr de-reference, and conform better to pkcs11. From Douglas Engert. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18187 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/hx509/ks_p11.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/hx509/ks_p11.c b/lib/hx509/ks_p11.c index a21d84b03..f97ca9967 100644 --- a/lib/hx509/ks_p11.c +++ b/lib/hx509/ks_p11.c @@ -950,16 +950,13 @@ p11_release_module(struct p11_module *p) if (--p->refcount > 0) return; - if (p->dl_handle) - dlclose(p->dl_handle); - for (i = 0; i < p->num_slots; i++) { - if (p->slot->flags & P11_SESSION_IN_USE) + if (p->slot[i].flags & P11_SESSION_IN_USE) _hx509_abort("pkcs11 module release while session in use"); - if (p->slot->flags & P11_SESSION) { + if (p->slot[i].flags & P11_SESSION) { int ret; - ret = P11FUNC(p, CloseSession, (p->slot->session)); + ret = P11FUNC(p, CloseSession, (p->slot[i].session)); if (ret != CKR_OK) ; } @@ -983,8 +980,15 @@ p11_release_module(struct p11_module *p) free(p->slot[i].mechs.infos); } } - free(p->slot); } + free(p->slot); + + if (p->funcs) + P11FUNC(p, Finalize, (NULL)); + + if (p->dl_handle) + dlclose(p->dl_handle); + memset(p, 0, sizeof(*p)); free(p); } @@ -1021,6 +1025,8 @@ p11_iter_start(hx509_context context, } for (i = 0 ; i < p->num_slots; i++) { + if (p->slot[i].certs == NULL) + continue; ret = hx509_certs_merge(context, c->certs, p->slot[i].certs); if (ret) { hx509_certs_free(&c->certs);