From d4ff84434265dc959098ccfd4e8cd5d61d9052c9 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Nov 11 2015 17:05:28 +0000 Subject: sss_client: Fix underflow of active_threads If the memory cache was not initialized and there was a failure in initialisation of memory cache context (e.g. memory cache file does not exist) then mc_context had to be destroyed to release resources. However the count of active threads in sss_cli_mc_ctx is already higher than zero because current thread is working wih the mc_context. But this counter was zero-ed with memset in sss_nss_mc_destroy_ctx due to issue with initialisation of memory cache. Then we have to decrease counter of active thread in function sss_nss_mc_get_ctx because initialisation of mc failed. And the result of this decrement is underflow of counter. Related to: https://fedorahosted.org/sssd/ticket/2726 Reviewed-by: Michal Židek --- diff --git a/src/sss_client/nss_mc_common.c b/src/sss_client/nss_mc_common.c index 707d124..92f802d 100644 --- a/src/sss_client/nss_mc_common.c +++ b/src/sss_client/nss_mc_common.c @@ -104,6 +104,8 @@ errno_t sss_nss_check_header(struct sss_cli_mc_ctx *ctx) static void sss_nss_mc_destroy_ctx(struct sss_cli_mc_ctx *ctx) { + uint32_t active_threads = ctx->active_threads; + if ((ctx->mmap_base != NULL) && (ctx->mmap_size != 0)) { munmap(ctx->mmap_base, ctx->mmap_size); } @@ -112,6 +114,9 @@ static void sss_nss_mc_destroy_ctx(struct sss_cli_mc_ctx *ctx) } memset(ctx, 0, sizeof(struct sss_cli_mc_ctx)); ctx->fd = -1; + + /* restore count of active threads */ + ctx->active_threads = active_threads; } static errno_t sss_nss_mc_init_ctx(const char *name,