Hello,

    Deallocate LDAP connections in safe way.

    Current code does isc_mem_detach() before isc_mem_put() so
    memory context reference counter is wrong for a small time frame.

    Macro MEM_PUT_AND_DETACH will handle it properly including
    pointer zeroing.

--
Petr^2 Spacek
From 15bc2ce1c854dab3ddf0a0521f59390aa8871fae Mon Sep 17 00:00:00 2001
From: Petr Spacek <pspa...@redhat.com>
Date: Tue, 20 Nov 2012 13:02:26 +0100
Subject: [PATCH] Deallocate LDAP connections in safe way.

Current code does isc_mem_detach() before isc_mem_put() so
memory context reference counter is wrong for a small time frame.

Macro MEM_PUT_AND_DETACH will handle it properly including
pointer zeroing.

Signed-off-by: Petr Spacek <pspa...@redhat.com>
---
 src/ldap_helper.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/ldap_helper.c b/src/ldap_helper.c
index 84ac06be7c7d4451e59844dd7c447f0f3d557f61..ef0fb69413d0febe8334bb5156d879fa1f0b9f16 100644
--- a/src/ldap_helper.c
+++ b/src/ldap_helper.c
@@ -258,8 +258,7 @@ struct ldap_psearchevent {
 /* TODO: reorganize this stuff & clean it up. */
 static isc_result_t new_ldap_connection(ldap_pool_t *pool,
 		ldap_connection_t **ldap_connp);
-static void destroy_ldap_connection(ldap_pool_t *pool,
-		ldap_connection_t **ldap_connp);
+static void destroy_ldap_connection(ldap_connection_t **ldap_connp);
 
 static isc_result_t findrdatatype_or_create(isc_mem_t *mctx,
 		ldapdb_rdatalist_t *rdatalist, dns_rdataclass_t rdclass,
@@ -706,13 +705,13 @@ new_ldap_connection(ldap_pool_t *pool, ldap_connection_t **ldap_connp)
 	return ISC_R_SUCCESS;
 
 cleanup:
-	destroy_ldap_connection(pool, &ldap_conn);
+	destroy_ldap_connection(&ldap_conn);
 
 	return result;
 }
 
 static void
-destroy_ldap_connection(ldap_pool_t *pool, ldap_connection_t **ldap_connp)
+destroy_ldap_connection(ldap_connection_t **ldap_connp)
 {
 	ldap_connection_t *ldap_conn;
 
@@ -730,10 +729,7 @@ destroy_ldap_connection(ldap_pool_t *pool, ldap_connection_t **ldap_connp)
 		ldap_control_free(ldap_conn->serverctrls[0]);
 	}
 
-	isc_mem_detach(&ldap_conn->mctx);
-
-	isc_mem_put(pool->mctx, *ldap_connp, sizeof(ldap_connection_t));
-	*ldap_connp = NULL;
+	MEM_PUT_AND_DETACH(*ldap_connp);
 }
 
 /*
@@ -3028,7 +3024,7 @@ ldap_pool_destroy(ldap_pool_t **poolp)
 	for (i = 0; i < pool->connections; i++) {
 		ldap_conn = pool->conns[i];
 		if (ldap_conn != NULL)
-			destroy_ldap_connection(pool, &ldap_conn);
+			destroy_ldap_connection(&ldap_conn);
 	}
 
 	SAFE_MEM_PUT(pool->mctx, pool->conns,
@@ -3109,7 +3105,7 @@ ldap_pool_connect(ldap_pool_t *pool, ldap_instance_t *ldap_inst)
 
 cleanup:
 	for (i = 0; i < pool->connections; i++) {
-		destroy_ldap_connection(pool, &pool->conns[i]);
+		destroy_ldap_connection(&pool->conns[i]);
 	}
 	return result;
 }
-- 
1.7.11.7

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to