On Tue, Nov 20, 2012 at 12:50:12PM +0100, Petr Spacek wrote:
> Hello,
> 
> this patch replaces all remaining occurrences of direct isc_mem_*
> calls  with macros.
> The only exception is destroy_ldap_connection() which will be
> handled in separate patch - current deallocation code is probably
> not safe.
> 
> Commit message:
>     Use memory allocation macros more extensively - part 2.
> 
>     Some scattered occurences of isc_mem_* functions was replaced by macros.
> 
>     String functions from str.c are still calling isc_mem_directly.

Ack

> From 9f44b8a965373f26c74100c84f7580d224355c3e Mon Sep 17 00:00:00 2001
> From: Petr Spacek <pspa...@redhat.com>
> Date: Tue, 20 Nov 2012 12:39:49 +0100
> Subject: [PATCH] Use memory allocation macros more extensively - part 2.
> 
> Some scattered occurrences of isc_mem_* functions was replaced by macros.
> 
> String functions from str.c are still calling isc_mem_directly.
> 
> Signed-off-by: Petr Spacek <pspa...@redhat.com>
> ---
>  src/acl.c           |  6 +-----
>  src/ldap_driver.c   |  2 +-
>  src/ldap_entry.c    |  6 +++---
>  src/ldap_helper.c   | 33 ++++++++++-----------------------
>  src/zone_manager.c  |  2 +-
>  src/zone_register.c |  2 +-
>  6 files changed, 17 insertions(+), 34 deletions(-)
> 
> diff --git a/src/acl.c b/src/acl.c
> index 
> a490affaded51b48f0406a5d5a7d0fa51f625d80..c62a8cb9e867b658b65ce05a07fc31377b2356c2
>  100644
> --- a/src/acl.c
> +++ b/src/acl.c
> @@ -553,11 +553,7 @@ acl_parse_forwarder(const char *forwarder_str, isc_mem_t 
> *mctx, isc_sockaddr_t *
>       }
>  
>       const cfg_obj_t *forwarder = cfg_listelt_value(element);
> -     *sa = isc_mem_get(mctx, sizeof(isc_sockaddr_t));
> -     if (*sa == NULL) {
> -             result = ISC_R_NOMEMORY;
> -             goto cleanup;
> -     }
> +     CHECKED_MEM_GET_PTR(mctx, *sa);
>       **sa = *cfg_obj_assockaddr(forwarder);
>       if (isc_sockaddr_getport(*sa) == 0)
>               isc_sockaddr_setport(*sa, port);
> diff --git a/src/ldap_driver.c b/src/ldap_driver.c
> index 
> 99a8421105f91a6c98d0e15d2c5962701974e380..cde09ee8aa3c9332f3766a031030a95b0cff3229
>  100644
> --- a/src/ldap_driver.c
> +++ b/src/ldap_driver.c
> @@ -221,7 +221,7 @@ clone_rdatalist_to_rdataset(isc_mem_t *mctx, 
> dns_rdatalist_t *rdlist,
>  cleanup:
>       if (new_rdlist != NULL) {
>               free_rdatalist(mctx, rdlist);
> -             isc_mem_put(mctx, new_rdlist, sizeof(*new_rdlist));
> +             SAFE_MEM_PUT_PTR(mctx, new_rdlist);
>       }
>  
>       return result;
> diff --git a/src/ldap_entry.c b/src/ldap_entry.c
> index 
> 1e165ca696ccafa177f17b97bda08ed9cc344c7d..9436b895913b2eb1a711d9343e43e695ea7e6ae4
>  100644
> --- a/src/ldap_entry.c
> +++ b/src/ldap_entry.c
> @@ -120,7 +120,7 @@ ldap_valuelist_destroy(isc_mem_t *mctx, ldap_valuelist_t 
> *values)
>       while (value != NULL) {
>               next = NEXT(value, link);
>               UNLINK(*values, value, link);
> -             isc_mem_put(mctx, value, sizeof(*value));
> +             SAFE_MEM_PUT_PTR(mctx, value);
>               value = next;
>       }
>  }
> @@ -137,7 +137,7 @@ ldap_attributelist_destroy(isc_mem_t *mctx, 
> ldap_attributelist_t *attrlist)
>               ldap_valuelist_destroy(mctx, &attr->values);
>                  ldap_value_free(attr->ldap_values);
>                  ldap_memfree(attr->name);
> -                isc_mem_put(mctx, attr, sizeof(*attr));
> +                SAFE_MEM_PUT_PTR(mctx, attr);
>                  attr = next;
>          }
>  }
> @@ -242,7 +242,7 @@ ldap_entry_destroy(isc_mem_t *mctx, ldap_entry_t **entryp)
>       ldap_attributelist_destroy(mctx, &entry->attrs);
>       if (entry->dn != NULL)
>               ldap_memfree(entry->dn);
> -     isc_mem_put(mctx, entry, sizeof(*entry));
> +     SAFE_MEM_PUT_PTR(mctx, entry);
>  
>       *entryp = NULL;
>  }
> diff --git a/src/ldap_helper.c b/src/ldap_helper.c
> index 
> 904bae5259cccd9ce5cfd27deead3a0d23864f84..84ac06be7c7d4451e59844dd7c447f0f3d557f61
>  100644
> --- a/src/ldap_helper.c
> +++ b/src/ldap_helper.c
> @@ -670,10 +670,10 @@ destroy_ldap_instance(ldap_instance_t **ldap_instp)
>       while (!ISC_LIST_EMPTY(ldap_inst->orig_global_forwarders.addrs)) {
>               addr = ISC_LIST_HEAD(ldap_inst->orig_global_forwarders.addrs);
>               ISC_LIST_UNLINK(ldap_inst->orig_global_forwarders.addrs, addr, 
> link);
> -             isc_mem_put(ldap_inst->mctx, addr, sizeof(isc_sockaddr_t));
> +             SAFE_MEM_PUT_PTR(ldap_inst->mctx, addr);
>       }
>  
> -     isc_mem_putanddetach(&ldap_inst->mctx, ldap_inst, 
> sizeof(ldap_instance_t));
> +     MEM_PUT_AND_DETACH(ldap_inst);
>  
>       *ldap_instp = NULL;
>       log_debug(1, "LDAP instance '%s' destroyed", db_name);
> @@ -693,7 +693,7 @@ new_ldap_connection(ldap_pool_t *pool, ldap_connection_t 
> **ldap_connp)
>  
>       result = isc_mutex_init(&ldap_conn->lock);
>       if (result != ISC_R_SUCCESS) {
> -             isc_mem_put(pool->mctx, ldap_conn, sizeof(ldap_connection_t));
> +             SAFE_MEM_PUT_PTR(pool->mctx, ldap_conn);
>               return result;
>       }
>  
> @@ -1135,7 +1135,7 @@ cleanup:
>                       isc_sockaddr_t *addr = NULL;
>                       addr = ISC_LIST_HEAD(addrs);
>                       ISC_LIST_UNLINK(addrs, addr, link);
> -                     isc_mem_put(inst->mctx, addr, sizeof(*addr));
> +                     SAFE_MEM_PUT_PTR(inst->mctx, addr);
>               }
>       }
>       if (fwdtbl_deletion_requested) {
> @@ -1654,7 +1654,7 @@ ldapdb_rdatalist_destroy(isc_mem_t *mctx, 
> ldapdb_rdatalist_t *rdatalist)
>               rdlist = HEAD(*rdatalist);
>               free_rdatalist(mctx, rdlist);
>               UNLINK(*rdatalist, rdlist, link);
> -             isc_mem_put(mctx, rdlist, sizeof(*rdlist));
> +             SAFE_MEM_PUT_PTR(mctx, rdlist);
>       }
>  }
>  
> @@ -1671,7 +1671,7 @@ free_rdatalist(isc_mem_t *mctx, dns_rdatalist_t *rdlist)
>               UNLINK(rdlist->rdata, rdata, link);
>               dns_rdata_toregion(rdata, &r);
>               isc_mem_put(mctx, r.base, r.length);
> -             isc_mem_put(mctx, rdata, sizeof(*rdata));
> +             SAFE_MEM_PUT_PTR(mctx, rdata);
>       }
>  }
>  
> @@ -1931,8 +1931,7 @@ parse_rdata(isc_mem_t *mctx, ldap_qresult_t *qresult,
>  
>  cleanup:
>       isc_lex_close(qresult->lex);
> -     if (rdata != NULL)
> -             isc_mem_put(mctx, rdata, sizeof(*rdata));
> +     SAFE_MEM_PUT_PTR(mctx, rdata);
>       if (rdatamem.base != NULL)
>               isc_mem_put(mctx, rdatamem.base, rdatamem.length);
>  
> @@ -3589,23 +3588,11 @@ psearch_update(ldap_instance_t *inst, ldap_entry_t 
> *entry, LDAPControl **ctrls)
>  
>       isc_mem_attach(inst->mctx, &mctx);
>  
> -     dn = isc_mem_strdup(mctx, entry->dn);
> -     if (dn == NULL) {
> -             result = ISC_R_NOMEMORY;
> -             goto cleanup;
> -     }
> -     dbname = isc_mem_strdup(mctx, inst->db_name);
> -     if (dbname == NULL) {
> -             result = ISC_R_NOMEMORY;
> -             goto cleanup;
> -     }
> +     CHECKED_MEM_STRDUP(mctx, entry->dn, dn);
> +     CHECKED_MEM_STRDUP(mctx, inst->db_name, dbname);
>  
>       if (PSEARCH_MODDN(chgtype)) {
> -             prevdn = isc_mem_strdup(mctx, prevdn_ldap);
> -             if (prevdn == NULL) {
> -                     result = ISC_R_NOMEMORY;
> -                     goto cleanup;
> -             }
> +             CHECKED_MEM_STRDUP(mctx, prevdn_ldap, prevdn);
>       }
>  
>       /*
> diff --git a/src/zone_manager.c b/src/zone_manager.c
> index 
> ca3edd010e5f6ea94adb57e5ae5e915a834e52a0..2988cfd0598de57efbc4f7a42447ad1dadce6d65
>  100644
> --- a/src/zone_manager.c
> +++ b/src/zone_manager.c
> @@ -98,7 +98,7 @@ destroy_db_instance(db_instance_t **db_instp)
>       if (db_inst->name != NULL)
>               isc_mem_free(db_inst->mctx, db_inst->name);
>  
> -     isc_mem_putanddetach(&db_inst->mctx, db_inst, sizeof(*db_inst));
> +     MEM_PUT_AND_DETACH(db_inst);
>  
>       *db_instp = NULL;
>  }
> diff --git a/src/zone_register.c b/src/zone_register.c
> index 
> 76305730b2e19686568f8a1bc6ac703ed3898fcc..18438bf937a6482ddf058adbecdc21e7cf2e7f26
>  100644
> --- a/src/zone_register.c
> +++ b/src/zone_register.c
> @@ -167,7 +167,7 @@ delete_zone_info(void *arg1, void *arg2)
>  
>       isc_mem_free(mctx, zinfo->dn);
>       dns_zone_detach(&zinfo->zone);
> -     isc_mem_put(mctx, zinfo, sizeof(*zinfo));
> +     SAFE_MEM_PUT_PTR(mctx, zinfo);
>  }
>  
>  /*
> -- 
> 1.7.11.7
> 


-- 
Adam Tkac, Red Hat, Inc.

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

Reply via email to