summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Slebodnik <lslebodn@redhat.com>2015-11-06 08:48:05 +0100
committerJakub Hrozek <jhrozek@redhat.com>2015-11-11 18:05:28 +0100
commitd4ff84434265dc959098ccfd4e8cd5d61d9052c9 (patch)
tree98931d534af90dbea59d5a6a65eb8788232a4bc4
parent356eef72675cde4dc5627c1e2f1a01846ec6eb1d (diff)
downloadsssd-d4ff84434265dc959098ccfd4e8cd5d61d9052c9.tar.gz
sssd-d4ff84434265dc959098ccfd4e8cd5d61d9052c9.tar.xz
sssd-d4ff84434265dc959098ccfd4e8cd5d61d9052c9.zip
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 <mzidek@redhat.com>
-rw-r--r--src/sss_client/nss_mc_common.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/sss_client/nss_mc_common.c b/src/sss_client/nss_mc_common.c
index 707d1249f..92f802db7 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,