From 4dcc33a770025f22095446266da18ba5521ad4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Sat, 8 Dec 2007 07:35:17 +0000 Subject: [PATCH] (_hx509_revoke_ref): new function. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@22214 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/hx509/revoke.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/hx509/revoke.c b/lib/hx509/revoke.c index c209b97c2..2ab981655 100644 --- a/lib/hx509/revoke.c +++ b/lib/hx509/revoke.c @@ -52,6 +52,7 @@ struct revoke_ocsp { struct hx509_revoke_ctx_data { + unsigned ref; struct { struct revoke_crl *val; size_t len; @@ -69,6 +70,7 @@ hx509_revoke_init(hx509_context context, hx509_revoke_ctx *ctx) if (*ctx == NULL) return ENOMEM; + (*ctx)->ref = 1; (*ctx)->crls.len = 0; (*ctx)->crls.val = NULL; (*ctx)->ocsps.len = 0; @@ -77,6 +79,17 @@ hx509_revoke_init(hx509_context context, hx509_revoke_ctx *ctx) return 0; } +hx509_revoke_ctx +_hx509_revoke_ref(hx509_revoke_ctx ctx) +{ + if (ctx->ref <= 0) + _hx509_abort("revoke ctx refcount <= 0"); + ctx->ref++; + if (ctx->ref == 0) + _hx509_abort("revoke ctx refcount == 0"); + return ctx; +} + static void free_ocsp(struct revoke_ocsp *ocsp) { @@ -94,6 +107,11 @@ hx509_revoke_free(hx509_revoke_ctx *ctx) if (ctx == NULL || *ctx == NULL) return; + if ((*ctx)->ref <= 0) + _hx509_abort("revoke ctx refcount <= 0 on free"); + if (--(*ctx)->ref > 0) + return; + for (i = 0; i < (*ctx)->crls.len; i++) { free((*ctx)->crls.val[i].path); free_CRLCertificateList(&(*ctx)->crls.val[i].crl);