From 1c4902378f6fad28da5ce221368bef136215b953 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Tue, 6 Dec 2022 15:15:15 -0600 Subject: [PATCH] base: Make heim_log_ref() thread-safe This is necessary to making multiple `krb5_context`s be able to share a log facility. --- lib/base/context.c | 2 +- lib/base/log.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/base/context.c b/lib/base/context.c index fb9b442ce..f22ce9459 100644 --- a/lib/base/context.c +++ b/lib/base/context.c @@ -159,7 +159,7 @@ heim_get_debug_dest(heim_context context) heim_error_code heim_set_log_dest(heim_context context, heim_log_facility *fac) { - context->log_dest = fac; + context->log_dest = heim_log_ref(fac); return 0; } diff --git a/lib/base/log.c b/lib/base/log.c index 1d79c7e45..618b6bc11 100644 --- a/lib/base/log.c +++ b/lib/base/log.c @@ -52,7 +52,7 @@ struct heim_log_facility_internal { struct heim_log_facility_s { char *program; - size_t refs; + volatile heim_base_atomic(size_t) refs; size_t len; struct heim_log_facility_internal *val; }; @@ -156,7 +156,7 @@ heim_log_facility * heim_log_ref(heim_log_facility *fac) { if (fac) - fac->refs++; + heim_base_atomic_inc(&fac->refs); return fac; } @@ -463,7 +463,7 @@ heim_closelog(heim_context context, heim_log_facility *fac) { int i; - if (!fac || --(fac->refs)) + if (!fac || heim_base_atomic_dec(&fac->refs)) return; for (i = 0; i < fac->len; i++) (*fac->val[i].close_func)(fac->val[i].data);