]> git.sur5r.net Git - openldap/commitdiff
ITS#4899 fix for keys not getting cleared
authorHoward Chu <hyc@openldap.org>
Sun, 1 Apr 2007 11:52:51 +0000 (11:52 +0000)
committerHoward Chu <hyc@openldap.org>
Sun, 1 Apr 2007 11:52:51 +0000 (11:52 +0000)
libraries/libldap_r/tpool.c

index 1b18ff8fe0ec5d4708f0ff6e6408b60028f317b0..1df006ae2202140c03044a47391f689f4dce6c8d 100644 (file)
@@ -825,10 +825,25 @@ int ldap_pvt_thread_pool_setkey(
        if ( !ctx || !key ) return EINVAL;
 
        for ( i=0; i<MAXKEYS; i++ ) {
-               if ( !ctx->ltu_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; j<MAXKEYS; j++ )
+                                       if ( !ctx->ltu_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;
                }
        }