From c80d5f970a7f1a9e05275cf3e5f16fea688606f5 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 1 Apr 2007 11:52:51 +0000 Subject: [PATCH] ITS#4899 fix for keys not getting cleared --- libraries/libldap_r/tpool.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/libraries/libldap_r/tpool.c b/libraries/libldap_r/tpool.c index 1b18ff8fe0..1df006ae22 100644 --- a/libraries/libldap_r/tpool.c +++ b/libraries/libldap_r/tpool.c @@ -825,10 +825,25 @@ int ldap_pvt_thread_pool_setkey( if ( !ctx || !key ) return EINVAL; for ( i=0; iltu_key[i].ltk_key || ctx->ltu_key[i].ltk_key == key ) { - ctx->ltu_key[i].ltk_key = key; - ctx->ltu_key[i].ltk_data = data; - ctx->ltu_key[i].ltk_free = kfree; + if (( data && !ctx->ltu_key[i].ltk_key ) || ctx->ltu_key[i].ltk_key == key ) { + if ( data || kfree ) { + ctx->ltu_key[i].ltk_key = key; + ctx->ltu_key[i].ltk_data = data; + ctx->ltu_key[i].ltk_free = kfree; + } else { + int j; + for ( j=i+1; jltu_key[j].ltk_key ) break; + j--; + if ( j != i ) { + ctx->ltu_key[i].ltk_key = ctx->ltu_key[j].ltk_key; + ctx->ltu_key[i].ltk_data = ctx->ltu_key[j].ltk_data; + ctx->ltu_key[i].ltk_free = ctx->ltu_key[j].ltk_free; + } + ctx->ltu_key[i].ltk_key = NULL; + ctx->ltu_key[i].ltk_data = NULL; + ctx->ltu_key[i].ltk_free = NULL; + } return 0; } } -- 2.39.5