[Freeipa-devel] [PATCH 0094] Use memory allocation macros more extensively - part 1

Adam Tkac atkac at redhat.com
Thu Nov 22 13:07:05 UTC 2012


On Tue, Nov 20, 2012 at 10:18:09AM +0100, Petr Spacek wrote:
> Hello,
> 
>     Use memory allocation macros more extensively.
> 
>     Some scattered occurences of isc_mem_* functions was replaced by macros.
>     Destroy_ldap_instance() now accepts NULL LDAP instance.
> 
>     String functions from str.c are still calling isc_mem_directly.
> 
> This patch contain small subset of changes which affect
> new_ldap_instance() and destroy_ldap_instance() calls. Remaining
> changes do not require changes in new_*/destroy_* logic and will
> follow in separate patch.

Ack

> From 47605bb5c605729224f43a01fcef94c93b7166d3 Mon Sep 17 00:00:00 2001
> From: Petr Spacek <pspacek at redhat.com>
> Date: Fri, 16 Nov 2012 15:34:39 +0100
> Subject: [PATCH] Use memory allocation macros more extensively.
> 
> Some scattered occurences of isc_mem_* functions was replaced by macros.
> Destroy_ldap_instance() now accepts NULL LDAP instance.
> 
> String functions from str.c are still calling isc_mem_directly.
> 
> Signed-off-by: Petr Spacek <pspacek at redhat.com>
> ---
>  src/ldap_helper.c | 21 ++++++++-------------
>  1 file changed, 8 insertions(+), 13 deletions(-)
> 
> diff --git a/src/ldap_helper.c b/src/ldap_helper.c
> index b36892b4e8180fb2a5f335e3fa1b5589dae8bf14..904bae5259cccd9ce5cfd27deead3a0d23864f84 100644
> --- a/src/ldap_helper.c
> +++ b/src/ldap_helper.c
> @@ -372,13 +372,10 @@ new_ldap_instance(isc_mem_t *mctx, const char *db_name,
>  
>  	REQUIRE(ldap_instp != NULL && *ldap_instp == NULL);
>  
> -	ldap_inst = isc_mem_get(mctx, sizeof(ldap_instance_t));
> -	if (ldap_inst == NULL)
> -		return ISC_R_NOMEMORY;
> -
> +	CHECKED_MEM_GET_PTR(mctx, ldap_inst);
>  	ZERO_PTR(ldap_inst);
> -
>  	isc_mem_attach(mctx, &ldap_inst->mctx);
> +
>  	ldap_inst->db_name = db_name;
>  	view = dns_dyndb_get_view(dyndb_args);
>  	dns_view_attach(view, &ldap_inst->view);
> @@ -511,9 +508,7 @@ new_ldap_instance(isc_mem_t *mctx, const char *db_name,
>  		for (addr = ISC_LIST_HEAD(orig_global_forwarders->addrs);
>  		     addr != NULL;
>  		     addr = ISC_LIST_NEXT(addr, link)) {
> -			new_addr = isc_mem_get(mctx, sizeof(isc_sockaddr_t));
> -			if (new_addr == NULL)
> -				CLEANUP_WITH(ISC_R_NOMEMORY);
> +			CHECKED_MEM_GET_PTR(mctx, new_addr);
>  			*new_addr = *addr;
>  			ISC_LINK_INIT(new_addr, link);
>  			ISC_LIST_APPEND(ldap_inst->orig_global_forwarders.addrs,
> @@ -561,9 +556,12 @@ destroy_ldap_instance(ldap_instance_t **ldap_instp)
>  	const char *db_name;
>  	isc_sockaddr_t *addr;
>  
> -	REQUIRE(ldap_instp != NULL && *ldap_instp != NULL);
> +	REQUIRE(ldap_instp != NULL);
>  
>  	ldap_inst = *ldap_instp;
> +	if (ldap_inst == NULL)
> +		return;
> +
>  	db_name = ldap_inst->db_name; /* points to DB instance: outside ldap_inst */
>  
>  	/*
> @@ -690,10 +688,7 @@ new_ldap_connection(ldap_pool_t *pool, ldap_connection_t **ldap_connp)
>  	REQUIRE(pool != NULL);
>  	REQUIRE(ldap_connp != NULL && *ldap_connp == NULL);
>  
> -	ldap_conn = isc_mem_get(pool->mctx, sizeof(ldap_connection_t));
> -	if (ldap_conn == NULL)
> -		return ISC_R_NOMEMORY;
> -
> +	CHECKED_MEM_GET_PTR(pool->mctx, ldap_conn);
>  	ZERO_PTR(ldap_conn);
>  
>  	result = isc_mutex_init(&ldap_conn->lock);
> -- 
> 1.7.11.7
> 


-- 
Adam Tkac, Red Hat, Inc.




More information about the Freeipa-devel mailing list