From a900898fce49cc70cc8721b5c550945c471d20b6 Mon Sep 17 00:00:00 2001 From: Martin Nagy Date: Wed, 25 Mar 2009 18:10:57 +0100 Subject: Add a convenience macro for isc_mem_allocate(). --- ldap_helper.c | 13 ++----------- util.h | 9 +++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ldap_helper.c b/ldap_helper.c index 73862e2..427191a 100644 --- a/ldap_helper.c +++ b/ldap_helper.c @@ -1613,11 +1613,7 @@ ldap_rdata_to_char_array(isc_mem_t *mctx, dns_rdata_t *rdata_head, vals_size = (rdata_count + 1) * sizeof(char *); - vals = isc_mem_allocate(mctx, vals_size); - if (vals == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } + CHECKED_MEM_ALLOCATE(mctx, vals, vals_size); memset(vals, 0, vals_size); rdata = rdata_head; @@ -1631,12 +1627,7 @@ ldap_rdata_to_char_array(isc_mem_t *mctx, dns_rdata_t *rdata_head, isc_buffer_usedregion(&buffer, ®ion); /* Now allocate the string with the right size. */ - vals[i] = isc_mem_allocate(mctx, region.length + 1); - if (vals[i] == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } - + CHECKED_MEM_ALLOCATE(mctx, vals[i], region.length + 1); memcpy(vals[i], region.base, region.length); vals[i][region.length] = '\0'; diff --git a/util.h b/util.h index 96abc51..372cd4d 100644 --- a/util.h +++ b/util.h @@ -25,6 +25,15 @@ if (result != ISC_R_SUCCESS) goto cleanup; \ } while (0) +#define CHECKED_MEM_ALLOCATE(m, target_ptr, s) \ + do { \ + (target_ptr) = isc_mem_allocate((m), (s)); \ + if ((target_ptr) == NULL) { \ + result = ISC_R_NOMEMORY; \ + goto cleanup; \ + } \ + } while (0) + #define CHECKED_MEM_GET(m, target_ptr, s) \ do { \ (target_ptr) = isc_mem_get((m), (s)); \ -- cgit