r4054: got rid of Realloc(), replacing it with the type safe macro realloc_p()
authorAndrew Tridgell <tridge@samba.org>
Fri, 3 Dec 2004 06:42:06 +0000 (06:42 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:06:19 +0000 (13:06 -0500)
source/client/client.c
source/lib/util.c
source/lib/util_file.c
source/lib/util_strlist.c
source/lib/wins_srv.c
source/libcli/auth/gensec.c
source/libcli/namequery.c
source/ntvfs/common/brlock.c
source/param/loadparm.c
source/param/params.c
source/smbd/process_model.c

index 6af145c31e9a2e46298d4561c11c98e734ddcce0..e4a7dc7cb5e9872b331a2d8d481fc20dd6a82147 100644 (file)
@@ -488,7 +488,7 @@ static void add_to_do_list_queue(const char* entry)
                do_list_queue_size *= 2;
                DEBUG(4,("enlarging do_list_queue to %d\n",
                         (int)do_list_queue_size));
-               dlq = Realloc(do_list_queue, do_list_queue_size);
+               dlq = realloc_p(do_list_queue, char, do_list_queue_size);
                if (! dlq) {
                        d_printf("failure enlarging do_list_queue to %d bytes\n",
                                 (int)do_list_queue_size);
index 2d149e6e3dcbecb75eb47337e27ad7cb94cc8bcc..ac5124840e8c7cc5f0c952c1690a3b7753869dea 100644 (file)
@@ -215,31 +215,6 @@ void become_daemon(BOOL Fork)
 }
 
 
-/****************************************************************************
- Expand a pointer to be a particular size.
-****************************************************************************/
-
-void *Realloc(void *p,size_t size)
-{
-       void *ret=NULL;
-
-       if (size == 0) {
-               SAFE_FREE(p);
-               DEBUG(5,("Realloc asked for 0 bytes\n"));
-               return NULL;
-       }
-
-       if (!p)
-               ret = (void *)malloc(size);
-       else
-               ret = (void *)realloc(p,size);
-
-       if (!ret)
-               DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size));
-
-       return(ret);
-}
-
 /****************************************************************************
  Free memory, checks for NULL.
  Use directly SAFE_FREE()
index 1dbaf1147e7c327ba8cfe31948ebc7edc6307e2e..f9697fb337642f8d469d6dce76fc5645386de3c6 100644 (file)
@@ -172,7 +172,7 @@ char *fgets_slash(char *s2,int maxlen,XFILE *f)
          char *t;
          
          maxlen *= 2;
-         t = (char *)Realloc(s,maxlen);
+         t = realloc_p(s, char, maxlen);
          if (!t) {
            DEBUG(0,("fgets_slash: failed to expand buffer!\n"));
            SAFE_FREE(s);
index a9198031a1af4c4d729c4dac9c78a1fbecba534f..33f824dcf846995ef86a01e245dc8bec91a4b00f 100644 (file)
@@ -53,7 +53,7 @@ char **str_list_make(const char *string, const char *sep)
        while (next_token(&str, tok, sep, sizeof(tok))) {               
                if (num == lsize) {
                        lsize += S_LIST_ABS;
-                       rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+                       rlist = realloc_p(list, char *, lsize + 1);
                        if (!rlist) {
                                DEBUG(0,("str_list_make: Unable to allocate memory"));
                                str_list_free(&list);
@@ -94,7 +94,7 @@ BOOL str_list_copy(char ***dest, const char **src)
        while (src[num]) {
                if (num == lsize) {
                        lsize += S_LIST_ABS;
-                       rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+                       rlist = realloc_p(list, char *, lsize + 1);
                        if (!rlist) {
                                DEBUG(0,("str_list_copy: Unable to re-allocate memory"));
                                str_list_free(&list);
@@ -302,7 +302,7 @@ int ipstr_list_parse(const char* ipstr_list, struct ipv4_addr** ip_list)
                        break;
                
                /* prepare place for another in_addr structure */
-               *ip_list = Realloc(*ip_list, (count + 1) * sizeof(struct ipv4_addr));
+               *ip_list = realloc_p(*ip_list, struct ipv4_addr, count + 1);
                if (!*ip_list) return -1;
                
                (*ip_list)[count] = addr;
index c9a5549cdc4c6b617d4388ec61d332cbca7b2748..094de8d6b09f8f57398df053e80da01e57c1051b 100644 (file)
@@ -238,7 +238,7 @@ char **wins_srv_tags(void)
                }
 
                /* add it to the list */
-               ret = (char **)Realloc(ret, (count+2) * sizeof(char *));
+               ret = realloc_p(ret, char *, count+2);
                ret[count] = strdup(t_ip.tag);
                if (!ret[count]) break;
                count++;
index 3cf96de4b3e55671985a6b6951a28f800f9bdae0..7243222b6d25a5a74d9c94cd58c34edc7cc17817 100644 (file)
@@ -770,7 +770,9 @@ NTSTATUS gensec_register(const void *_ops)
                return NT_STATUS_OBJECT_NAME_COLLISION;
        }
 
-       generic_security_ops = Realloc(generic_security_ops, sizeof(generic_security_ops[0]) * (gensec_num_backends+1));
+       generic_security_ops = realloc_p(generic_security_ops, 
+                                        const struct gensec_security_ops *, 
+                                        gensec_num_backends+1);
        if (!generic_security_ops) {
                smb_panic("out of memory in gensec_register");
        }
index 66154ef8f6549e4c9b2dadd90f8c4f7a1d274321..76fffe0d9276567c37b18501da90b66c4a7c5a21 100644 (file)
@@ -400,11 +400,12 @@ struct ipv4_addr *name_query(int fd,const char *name,int name_type,
                                continue;
                        }
                        
-                       tmp_ip_list = (struct ipv4_addr *)Realloc( ip_list, sizeof( ip_list[0] )
-                                                                * ( (*count) + nmb2->answers->rdlength/6 ) );
+                       tmp_ip_list = realloc_p(ip_list, 
+                                               struct ipv4_addr,
+                                               (*count) + nmb2->answers->rdlength/6);
                        
                        if (!tmp_ip_list) {
-                               DEBUG(0,("name_query: Realloc failed.\n"));
+                               DEBUG(0,("name_query: realloc_p failed.\n"));
                                SAFE_FREE(ip_list);
                        }
                        
index e01f458e7444abf76ab4f33e8ea8a7eb26690774..7b351f77b0c8ac7bbbe8edc5e34c6aaef7605efa 100644 (file)
@@ -229,9 +229,8 @@ NTSTATUS brl_lock(struct brl_context *brl,
                  void *notify_ptr)
 {
        TDB_DATA kbuf, dbuf;
-       int count, i;
-       struct lock_struct lock, *locks;
-       char *tp;
+       int count=0, i;
+       struct lock_struct lock, *locks=NULL;
        NTSTATUS status;
 
        kbuf.dptr = (char *)file_key->data;
@@ -279,14 +278,14 @@ NTSTATUS brl_lock(struct brl_context *brl,
        }
 
        /* no conflicts - add it to the list of locks */
-       tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(*locks));
-       if (!tp) {
+       locks = realloc_p(locks, struct lock_struct, count+1);
+       if (!locks) {
                status = NT_STATUS_NO_MEMORY;
                goto fail;
        } else {
-               dbuf.dptr = tp;
+               dbuf.dptr = (char *)locks;
        }
-       memcpy(dbuf.dptr + dbuf.dsize, &lock, sizeof(lock));
+       locks[count] = lock;
        dbuf.dsize += sizeof(lock);
 
        if (tdb_store(brl->w->tdb, kbuf, dbuf, TDB_REPLACE) != 0) {
index 1d9553de3e12a13a2eab2f9742b56b9a87536923..8975f066fa9205af047b20b865a3e2841e43ad64 100644 (file)
@@ -1568,9 +1568,7 @@ static int add_a_service(const service *pservice, const char *name)
        if (i == iNumServices) {
                service **tsp;
                
-               tsp = (service **) Realloc(ServicePtrs,
-                                          sizeof(service *) *
-                                          num_to_alloc);
+               tsp = realloc_p(ServicePtrs, service *, num_to_alloc);
                                           
                if (!tsp) {
                        DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
index a31d8d1b605aff139d0d525fd14e178644d320ac..1b5b02cfa35d655d0d10a0f70b3fb4a68ee4cd69 100644 (file)
@@ -239,7 +239,7 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) )
       {
       char *tb;
       
-      tb = Realloc( bufr, bSize +BUFR_INC );
+      tb = realloc_p(bufr, char, bSize + BUFR_INC);
       if( NULL == tb )
         {
         DEBUG(0, ("%s Memory re-allocation failure.", func) );
@@ -336,7 +336,7 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *)
       {
       char *tb;
       
-      tb = Realloc( bufr, bSize + BUFR_INC );
+      tb = realloc_p( bufr, char, bSize + BUFR_INC );
       if( NULL == tb )
         {
         DEBUG(0, ("%s Memory re-allocation failure.", func) );
@@ -404,7 +404,7 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *)
       {
       char *tb;
       
-      tb = Realloc( bufr, bSize + BUFR_INC );
+      tb = realloc_p( bufr, char, bSize + BUFR_INC );
       if( NULL == tb )
         {
         DEBUG(0, ("%s Memory re-allocation failure.", func) );
index 2a3efe2088f1f460dff456cdb2125854253f14a2..ad9a26d377598d579c4b68e94685181793221eb6 100644 (file)
@@ -43,7 +43,7 @@ const struct model_ops *process_model_startup(const char *model)
 }
 
 /* the list of currently registered process models */
-static struct {
+static struct process_model {
        struct model_ops *ops;
 } *models = NULL;
 static int num_models;
@@ -65,7 +65,7 @@ NTSTATUS register_process_model(const void *_ops)
                return NT_STATUS_OBJECT_NAME_COLLISION;
        }
 
-       models = Realloc(models, sizeof(models[0]) * (num_models+1));
+       models = realloc_p(models, struct process_model, num_models+1);
        if (!models) {
                smb_panic("out of memory in register_process_model");
        }