r4291: More *alloc fixes inspired by Albert Chin (china@thewrittenword.com).
authorJeremy Allison <jra@samba.org>
Mon, 20 Dec 2004 21:14:28 +0000 (21:14 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:53:42 +0000 (10:53 -0500)
Jeremy

source/client/tree.c
source/lib/afs_settoken.c
source/lib/sysacls.c
source/lib/util_smbd.c
source/libsmb/clikrb5.c
source/modules/vfs_afsacl.c
source/utils/editreg.c
source/utils/net_rpc_samsync.c

index 97ad7742e314fe1b7a861a0efc87cfaa8cd31710..5071c45dbc97412a04872c0124daf094a3128a3b 100644 (file)
@@ -129,7 +129,7 @@ char *get_path(GtkWidget *item)
 
 struct tree_data *make_tree_data(guint32 type, const char *name)
 {
-  struct tree_data *p = (struct tree_data *)malloc(sizeof(struct tree_data));
+  struct tree_data *p = SMB_MALLOC_P(struct tree_data);
 
   if (p) {
 
index 5c646c72e48028cc59a022d8658d4049b95b1ac6..2e74328d5d6559611bf701aa490024469ec68e1d 100644 (file)
@@ -53,7 +53,7 @@ static BOOL afs_decode_token(const char *string, char **cell,
        DATA_BLOB blob;
        struct ClearToken result_ct;
 
-       char *s = strdup(string);
+       char *s = SMB_STRDUP(string);
 
        char *t;
 
@@ -62,7 +62,7 @@ static BOOL afs_decode_token(const char *string, char **cell,
                return False;
        }
 
-       *cell = strdup(t);
+       *cell = SMB_STRDUP(t);
 
        if ((t = strtok(NULL, "\n")) == NULL) {
                DEBUG(10, ("strtok failed\n"));
index 9b5bef00e8acc1250112c63a6361cee850a34a03..f5801af8c55aec9692074f9397656590cc5a5562 100644 (file)
@@ -612,7 +612,7 @@ char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
         */
        len     = 0;
        maxlen  = 20 * acl_d->count;
-       if ((text = malloc(maxlen)) == NULL) {
+       if ((text = SMB_MALLOC(maxlen)) == NULL) {
                errno = ENOMEM;
                return NULL;
        }
@@ -690,7 +690,7 @@ char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
 
                        maxlen += nbytes + 20 * (acl_d->count - i);
 
-                       if ((text = Realloc(oldtext, maxlen)) == NULL) {
+                       if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
                                SAFE_FREE(oldtext);
                                errno = ENOMEM;
                                return NULL;
@@ -722,7 +722,7 @@ SMB_ACL_T sys_acl_init(int count)
         * acl[] array, this actually allocates an ACL with room
         * for (count+1) entries
         */
-       if ((a = malloc(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
+       if ((a = SMB_MALLOC(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
                errno = ENOMEM;
                return NULL;
        }
@@ -886,7 +886,7 @@ int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
                 * allocate a temporary buffer for the complete ACL
                 */
                acl_count = acc_acl->count + def_acl->count;
-               acl_p = acl_buf = malloc(acl_count * sizeof(acl_buf[0]));
+               acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
 
                if (acl_buf == NULL) {
                        sys_acl_free_acl(tmp_acl);
@@ -1243,7 +1243,7 @@ char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
         */
        len     = 0;
        maxlen  = 20 * acl_d->count;
-       if ((text = malloc(maxlen)) == NULL) {
+       if ((text = SMB_MALLOC(maxlen)) == NULL) {
                errno = ENOMEM;
                return NULL;
        }
@@ -1321,7 +1321,7 @@ char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
 
                        maxlen += nbytes + 20 * (acl_d->count - i);
 
-                       if ((text = Realloc(oldtext, maxlen)) == NULL) {
+                       if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
                                free(oldtext);
                                errno = ENOMEM;
                                return NULL;
@@ -1353,7 +1353,7 @@ SMB_ACL_T sys_acl_init(int count)
         * acl[] array, this actually allocates an ACL with room
         * for (count+1) entries
         */
-       if ((a = malloc(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
+       if ((a = SMB_MALLOC(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
                errno = ENOMEM;
                return NULL;
        }
@@ -1819,7 +1819,7 @@ int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
                 * allocate a temporary buffer for the complete ACL
                 */
                acl_count = acc_acl->count + def_acl->count;
-               acl_p = acl_buf = malloc(acl_count * sizeof(acl_buf[0]));
+               acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
 
                if (acl_buf == NULL) {
                        sys_acl_free_acl(tmp_acl);
@@ -1982,7 +1982,7 @@ SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
 {
        SMB_ACL_T       a;
 
-       if ((a = malloc(sizeof(*a))) == NULL) {
+       if ((a = SMB_MALLOC_P(SMB_ACL_T)) == NULL) {
                errno = ENOMEM;
                return NULL;
        }
@@ -1999,7 +1999,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
 {
        SMB_ACL_T       a;
 
-       if ((a = malloc(sizeof(*a))) == NULL) {
+       if ((a = SMB_MALLOC_P(SMB_ACL_T)) == NULL) {
                errno = ENOMEM;
                return NULL;
        }
@@ -2056,7 +2056,7 @@ SMB_ACL_T sys_acl_init(int count)
                return NULL;
        }
 
-       if ((a = malloc(sizeof(*a) + sizeof(struct acl))) == NULL) {
+       if ((a = SMB_MALLOC_P(struct acl)) == NULL) {
                errno = ENOMEM;
                return NULL;
        }
@@ -2282,7 +2282,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
        DEBUG(10,("Entering sys_acl_get_file\n"));
        DEBUG(10,("path_p is %s\n",path_p));
 
-       file_acl = (struct acl *)malloc(BUFSIZ);
+       file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
  
        if(file_acl == NULL) {
                errno=ENOMEM;
@@ -2313,7 +2313,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
        if(acl_entry_link_head == NULL)
                return(NULL);
 
-       acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
+       acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
        if(acl_entry_link->entryp == NULL) {
                SAFE_FREE(file_acl);
                errno = ENOMEM;
@@ -2348,8 +2348,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
                         * and already has entryp allocated.                  */
 
                        if(acl_entry_link_head->count != 0) {
-                               acl_entry_link->nextp = (struct acl_entry_link *)
-                                                                                       malloc(sizeof(struct acl_entry_link));
+                               acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
 
                                if(acl_entry_link->nextp == NULL) {
                                        SAFE_FREE(file_acl);
@@ -2360,7 +2359,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
 
                                acl_entry_link->nextp->prevp = acl_entry_link;
                                acl_entry_link = acl_entry_link->nextp;
-                               acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
+                               acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
                                if(acl_entry_link->entryp == NULL) {
                                        SAFE_FREE(file_acl);
                                        errno = ENOMEM;
@@ -2419,7 +2418,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
        for( i = 1; i < 4; i++) {
                DEBUG(10,("i is %d\n",i));
                if(acl_entry_link_head->count != 0) {
-                       acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
+                       acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
                        if(acl_entry_link->nextp == NULL) {
                                SAFE_FREE(file_acl);
                                errno = ENOMEM;
@@ -2429,7 +2428,7 @@ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
 
                        acl_entry_link->nextp->prevp = acl_entry_link;
                        acl_entry_link = acl_entry_link->nextp;
-                       acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
+                       acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
                        if(acl_entry_link->entryp == NULL) {
                                SAFE_FREE(file_acl);
                                errno = ENOMEM;
@@ -2496,7 +2495,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
    
        DEBUG(10,("Entering sys_acl_get_fd\n"));
        DEBUG(10,("fd is %d\n",fd));
-       file_acl = (struct acl *)malloc(BUFSIZ);
+       file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
 
        if(file_acl == NULL) {
                errno=ENOMEM;
@@ -2529,7 +2528,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
                return(NULL);
        }
 
-       acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
+       acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
 
        if(acl_entry_link->entryp == NULL) {
                errno = ENOMEM;
@@ -2566,7 +2565,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
                         * and already has entryp allocated.                 */
 
                        if(acl_entry_link_head->count != 0) {
-                               acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
+                               acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
                                if(acl_entry_link->nextp == NULL) {
                                        errno = ENOMEM;
                                        DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
@@ -2575,7 +2574,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
                                }
                                acl_entry_link->nextp->prevp = acl_entry_link;
                                acl_entry_link = acl_entry_link->nextp;
-                               acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
+                               acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
                                if(acl_entry_link->entryp == NULL) {
                                        errno = ENOMEM;
                                        DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
@@ -2634,7 +2633,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
        for( i = 1; i < 4; i++) {
                DEBUG(10,("i is %d\n",i));
                if(acl_entry_link_head->count != 0){
-                       acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
+                       acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
                        if(acl_entry_link->nextp == NULL) {
                                errno = ENOMEM;
                                DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
@@ -2644,7 +2643,7 @@ SMB_ACL_T sys_acl_get_fd(int fd)
 
                        acl_entry_link->nextp->prevp = acl_entry_link;
                        acl_entry_link = acl_entry_link->nextp;
-                       acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
+                       acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
 
                        if(acl_entry_link->entryp == NULL) {
                                SAFE_FREE(file_acl);
@@ -2723,7 +2722,7 @@ SMB_ACL_T sys_acl_init( int count)
  
        DEBUG(10,("Entering sys_acl_init\n"));
 
-       theacl = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
+       theacl = SMB_MALLOC_P(struct acl_entry_link);
        if(theacl == NULL) {
                errno = ENOMEM;
                DEBUG(0,("Error in sys_acl_init is %d\n",errno));
@@ -2758,7 +2757,7 @@ int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
        }
 
        if(theacl->count != 0){
-               temp_entry->nextp = acl_entryp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
+               temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
                if(acl_entryp == NULL) {
                        errno = ENOMEM;
                        DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
@@ -2770,7 +2769,7 @@ int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
                DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
        }
 
-       *pentry = acl_entryp->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
+       *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
        if(*pentry == NULL) {
                errno = ENOMEM;
                DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
@@ -2860,7 +2859,7 @@ int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl
                return(0);
 
        acl_length = BUFSIZ;
-       file_acl = (struct acl *)malloc(BUFSIZ);
+       file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
 
        if(file_acl == NULL) {
                errno = ENOMEM;
@@ -2893,7 +2892,7 @@ int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl
 
                if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
                        acl_length += sizeof(struct acl_entry);
-                       file_acl_temp = (struct acl *)malloc(acl_length);
+                       file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
                        if(file_acl_temp == NULL) {
                                SAFE_FREE(file_acl);
                                errno = ENOMEM;
@@ -2948,7 +2947,7 @@ int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
  
        DEBUG(10,("Entering sys_acl_set_fd\n"));
        acl_length = BUFSIZ;
-       file_acl = (struct acl *)malloc(BUFSIZ);
+       file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
 
        if(file_acl == NULL) {
                errno = ENOMEM;
@@ -2982,7 +2981,7 @@ int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
 
                if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
                        acl_length += sizeof(struct acl_entry);
-                       file_acl_temp = (struct acl *)malloc(acl_length);
+                       file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
                        if(file_acl_temp == NULL) {
                                SAFE_FREE(file_acl);
                                errno = ENOMEM;
index fdb4cb3385920c93a7b4179ce32d4e3fae4f0330..2eb0bb7cc07bb7930673f6552b27af9be438008c 100644 (file)
@@ -45,7 +45,7 @@ BOOL getgroups_user(const char *user, gid_t primary_gid, gid_t **ret_groups, int
        int i;
 
        max_grp = groups_max();
-       temp_groups = (gid_t *)malloc(sizeof(gid_t) * max_grp);
+       temp_groups = SMB_MALLOC_P(gid_t, max_grp);
        if (! temp_groups) {
                return False;
        }
@@ -54,7 +54,7 @@ BOOL getgroups_user(const char *user, gid_t primary_gid, gid_t **ret_groups, int
                
                gid_t *groups_tmp;
                
-               groups_tmp = Realloc(temp_groups, sizeof(gid_t) * max_grp);
+               groups_tmp = SMB_REALLOC(temp_groups, gid_t, max_grp);
                
                if (!groups_tmp) {
                        SAFE_FREE(temp_groups);
index 15be8967b843b828b791a411417b34ad92a659de..66c16b69aef4c4b882eae2f0122e46d0dd58e497 100644 (file)
                return -1;
        }
 
-       sa = malloc( sizeof(struct sockaddr) * num_kdcs );
+       sa = SMB_MALLOC_ARRAY( struct sockaddr, num_kdcs );
        if (!sa) {
                DEBUG(0, ("krb5_locate_kdc: malloc failed\n"));
                krb5_krbhst_free(ctx, hnd);
                return -1;
        }
 
-       *addr_pp = malloc(sizeof(struct sockaddr) * num_kdcs);
-       memset(*addr_pp, '\0', sizeof(struct sockaddr) * num_kdcs );
+       memset(sa, '\0', sizeof(struct sockaddr) * num_kdcs );
 
        for (i = 0; i < num_kdcs && (rc = krb5_krbhst_next(ctx, hnd, &hinfo) == 0); i++) {
 
index bb82801a00b1d8781469c49c2d5de017052a0a67..6d6848eb120e2d3e7e4967ff00c64419c3192cd7 100644 (file)
@@ -85,7 +85,7 @@ static void free_afs_acl(struct afs_acl *acl)
 
 static struct afs_ace *clone_afs_ace(TALLOC_CTX *mem_ctx, struct afs_ace *ace)
 {
-       struct afs_ace *result = talloc(mem_ctx, sizeof(struct afs_ace));
+       struct afs_ace *result = TALLOC_P(mem_ctx, struct afs_ace);
 
        if (result == NULL)
                return NULL;
@@ -169,7 +169,7 @@ static struct afs_ace *new_afs_ace(TALLOC_CTX *mem_ctx,
                }
        }
 
-       result = talloc(mem_ctx, sizeof(struct afs_ace));
+       result = TALLOC_P(mem_ctx, struct afs_ace);
 
        if (result == NULL) {
                DEBUG(0, ("Could not talloc AFS ace\n"));
@@ -619,7 +619,7 @@ static size_t afs_to_nt_acl(struct afs_acl *afs_acl,
        uid_to_sid(&owner_sid, sbuf.st_uid);
        gid_to_sid(&group_sid, sbuf.st_gid);
 
-       nt_ace_list = (SEC_ACE *)malloc(afs_acl->num_aces * sizeof(SEC_ACE));
+       nt_ace_list = SMB_MALLOC_ARRAY(SEC_ACE, afs_acl->num_aces);
 
        if (nt_ace_list == NULL)
                return 0;
index fa930b163aa3500a9781737dd73bac5edb011b9d..9123de18c87bbc0d57e7deab64deba2aa3147e5d 100644 (file)
@@ -302,6 +302,7 @@ Hope this helps....  (Although it was "fun" for me to uncover this things,
 
 *************************************************************************/
 
+#ifdef STANDALONE
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -315,6 +316,10 @@ Hope this helps....  (Although it was "fun" for me to uncover this things,
 
 #define False 0
 #define True 1
+#else /* STANDALAONE */
+#include "includes.h"
+#endif /* STANDALONE */
+
 #define REG_KEY_LIST_SIZE 10
 
 /*
@@ -1900,7 +1905,7 @@ SEC_DESC *process_sec_desc(REGF *regf, REG_SEC_DESC *sec_desc)
 {
   SEC_DESC *tmp = NULL;
   
-  tmp = (SEC_DESC *)malloc(sizeof(SEC_DESC));
+  tmp = SMB_MALLOC_P(SEC_DESC);
 
   if (!tmp) {
     return NULL;
index 3c98ec9e713a9595d2c01524799e2006e8e10fa2..e8a110d083e5edfc15c8b619cc08528c3472b848 100644 (file)
@@ -863,7 +863,7 @@ fetch_alias_mem(uint32 rid, SAM_ALIAS_MEM_INFO *delta, DOM_SID dom_sid)
                return NT_STATUS_NO_MEMORY;
        }
 
-       nt_members = talloc_zero(t, sizeof(char *) * delta->num_members);
+       nt_members = TALLOC_ZERO_ARRAY(t, char *, delta->num_members);
 
        for (i=0; i<delta->num_members; i++) {
                NTSTATUS nt_status;