diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/examples/VFS/shadow_copy_test.c samba-3.0.9/examples/VFS/shadow_copy_test.c --- samba-3.0.9-orig/examples/VFS/shadow_copy_test.c 2004-11-15 21:03:50.000000000 -0600 +++ samba-3.0.9/examples/VFS/shadow_copy_test.c 2004-12-09 09:00:27.612513224 -0600 @@ -58,7 +58,7 @@ shadow_copy_data->num_volumes = num; if (labels) { - shadow_copy_data->labels = (SHADOW_COPY_LABEL *)talloc_zero(shadow_copy_data->mem_ctx,(num)*sizeof(SHADOW_COPY_LABEL)); + shadow_copy_data->labels = TALLOC_ZERO_ARRAY(shadow_copy_data->mem_ctx,SHADOW_COPY_LABEL,num); for (i=0;ilabels[i], sizeof(SHADOW_COPY_LABEL), "@GMT-2003.08.05-12.%02u.00",i); } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/auth/auth.c samba-3.0.9/source/auth/auth.c --- samba-3.0.9-orig/source/auth/auth.c 2004-11-15 21:03:16.000000000 -0600 +++ samba-3.0.9/source/auth/auth.c 2004-12-09 09:00:27.128633441 -0600 @@ -49,7 +49,7 @@ return NT_STATUS_OBJECT_NAME_COLLISION; } - entry = smb_xmalloc(sizeof(struct auth_init_function_entry)); + entry = SMB_XMALLOC_P(struct auth_init_function_entry); entry->name = smb_xstrdup(name); entry->init = init; @@ -347,7 +347,7 @@ mem_ctx = talloc_init("authentication context"); - *auth_context = talloc(mem_ctx, sizeof(**auth_context)); + *auth_context = TALLOC_P(mem_ctx, struct auth_context); if (!*auth_context) { DEBUG(0,("make_auth_context: talloc failed!\n")); talloc_destroy(mem_ctx); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/auth/auth_ntlmssp.c samba-3.0.9/source/auth/auth_ntlmssp.c --- samba-3.0.9-orig/source/auth/auth_ntlmssp.c 2004-11-15 21:03:16.000000000 -0600 +++ samba-3.0.9/source/auth/auth_ntlmssp.c 2004-12-09 09:00:27.129633193 -0600 @@ -135,7 +135,7 @@ mem_ctx = talloc_init("AUTH NTLMSSP context"); - *auth_ntlmssp_state = talloc_zero(mem_ctx, sizeof(**auth_ntlmssp_state)); + *auth_ntlmssp_state = TALLOC_ZERO_P(mem_ctx, AUTH_NTLMSSP_STATE); if (!*auth_ntlmssp_state) { DEBUG(0,("auth_ntlmssp_start: talloc failed!\n")); talloc_destroy(mem_ctx); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/auth/auth_util.c samba-3.0.9/source/auth/auth_util.c --- samba-3.0.9-orig/source/auth/auth_util.c 2004-11-15 21:03:16.000000000 -0600 +++ samba-3.0.9/source/auth/auth_util.c 2004-12-09 09:00:27.123634683 -0600 @@ -132,7 +132,7 @@ DEBUG(5,("attempting to make a user_info for %s (%s)\n", internal_username, smb_name)); - *user_info = malloc(sizeof(**user_info)); + *user_info = SMB_MALLOC_P(auth_usersupplied_info); if (!user_info) { DEBUG(0,("malloc failed for user_info (size %lu)\n", (unsigned long)sizeof(*user_info))); return NT_STATUS_NO_MEMORY; @@ -142,7 +142,7 @@ DEBUG(5,("making strings for %s's user_info struct\n", internal_username)); - (*user_info)->smb_name.str = strdup(smb_name); + (*user_info)->smb_name.str = SMB_STRDUP(smb_name); if ((*user_info)->smb_name.str) { (*user_info)->smb_name.len = strlen(smb_name); } else { @@ -150,7 +150,7 @@ return NT_STATUS_NO_MEMORY; } - (*user_info)->internal_username.str = strdup(internal_username); + (*user_info)->internal_username.str = SMB_STRDUP(internal_username); if ((*user_info)->internal_username.str) { (*user_info)->internal_username.len = strlen(internal_username); } else { @@ -158,7 +158,7 @@ return NT_STATUS_NO_MEMORY; } - (*user_info)->domain.str = strdup(domain); + (*user_info)->domain.str = SMB_STRDUP(domain); if ((*user_info)->domain.str) { (*user_info)->domain.len = strlen(domain); } else { @@ -166,7 +166,7 @@ return NT_STATUS_NO_MEMORY; } - (*user_info)->client_domain.str = strdup(client_domain); + (*user_info)->client_domain.str = SMB_STRDUP(client_domain); if ((*user_info)->client_domain.str) { (*user_info)->client_domain.len = strlen(client_domain); } else { @@ -174,7 +174,7 @@ return NT_STATUS_NO_MEMORY; } - (*user_info)->wksta_name.str = strdup(wksta_name); + (*user_info)->wksta_name.str = SMB_STRDUP(wksta_name); if ((*user_info)->wksta_name.str) { (*user_info)->wksta_name.len = strlen(wksta_name); } else { @@ -523,7 +523,7 @@ int i; int sid_ndx; - if ((ptoken = malloc( sizeof(NT_USER_TOKEN) ) ) == NULL) { + if ((ptoken = SMB_MALLOC_P(NT_USER_TOKEN)) == NULL) { DEBUG(0, ("create_nt_token: Out of memory allocating token\n")); nt_status = NT_STATUS_NO_MEMORY; return nt_status; @@ -533,7 +533,7 @@ ptoken->num_sids = n_groupSIDs + 5; - if ((ptoken->user_sids = (DOM_SID *)malloc( sizeof(DOM_SID) * ptoken->num_sids )) == NULL) { + if ((ptoken->user_sids = SMB_MALLOC_ARRAY( DOM_SID, ptoken->num_sids )) == NULL) { DEBUG(0, ("create_nt_token: Out of memory allocating SIDs\n")); nt_status = NT_STATUS_NO_MEMORY; return nt_status; @@ -610,7 +610,7 @@ return NULL; } - group_sids = malloc(sizeof(DOM_SID) * ngroups); + group_sids = SMB_MALLOC_ARRAY(DOM_SID, ngroups); if (!group_sids) { DEBUG(0, ("create_nt_token: malloc() failed for DOM_SID list!\n")); return NULL; @@ -674,7 +674,7 @@ n_unix_groups = groups_max(); - if ((*unix_groups = malloc( sizeof(gid_t) * n_unix_groups ) ) == NULL) { + if ((*unix_groups = SMB_MALLOC_ARRAY( gid_t, n_unix_groups ) ) == NULL) { DEBUG(0, ("get_user_groups: Out of memory allocating unix group list\n")); return NT_STATUS_NO_MEMORY; } @@ -683,7 +683,7 @@ gid_t *groups_tmp; - groups_tmp = Realloc(*unix_groups, sizeof(gid_t) * n_unix_groups); + groups_tmp = SMB_REALLOC_ARRAY(*unix_groups, gid_t, n_unix_groups); if (!groups_tmp) { SAFE_FREE(*unix_groups); @@ -705,7 +705,7 @@ if (n_unix_groups > 0) { - *groups = malloc(sizeof(DOM_SID) * n_unix_groups); + *groups = SMB_MALLOC_ARRAY(DOM_SID, n_unix_groups); if (!*groups) { DEBUG(0, ("get_user_group: malloc() failed for DOM_SID list!\n")); @@ -735,7 +735,7 @@ static NTSTATUS make_server_info(auth_serversupplied_info **server_info) { - *server_info = malloc(sizeof(**server_info)); + *server_info = SMB_MALLOC_P(auth_serversupplied_info); if (!*server_info) { DEBUG(0,("make_server_info: malloc failed!\n")); return NT_STATUS_NO_MEMORY; @@ -1221,7 +1221,7 @@ /* Create a 'combined' list of all SIDs we might want in the SD */ - all_group_SIDs = malloc(sizeof(DOM_SID) * (info3->num_groups2 + info3->num_other_sids + n_lgroupSIDs)); + all_group_SIDs = SMB_MALLOC_ARRAY(DOM_SID,info3->num_groups2 + info3->num_other_sids + n_lgroupSIDs); if (!all_group_SIDs) { DEBUG(0, ("malloc() failed for DOM_SID list!\n")); @@ -1370,7 +1370,7 @@ smb_panic("make_auth_methods: pointer to auth_method pointer is NULL!\n"); } - *auth_method = talloc(auth_context->mem_ctx, sizeof(**auth_method)); + *auth_method = TALLOC_P(auth_context->mem_ctx, auth_methods); if (!*auth_method) { DEBUG(0,("make_auth_method: malloc failed!\n")); return False; @@ -1405,7 +1405,7 @@ if (!ptoken) return NULL; - if ((token = (NT_USER_TOKEN *)malloc( sizeof(NT_USER_TOKEN) ) ) == NULL) + if ((token = SMB_MALLOC_P(NT_USER_TOKEN)) == NULL) return NULL; ZERO_STRUCTP(token); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/client/client.c samba-3.0.9/source/client/client.c --- samba-3.0.9-orig/source/client/client.c 2004-11-15 21:03:35.000000000 -0600 +++ samba-3.0.9/source/client/client.c 2004-12-09 09:00:27.606514715 -0600 @@ -387,7 +387,7 @@ { reset_do_list_queue(); do_list_queue_size = 1024; - do_list_queue = malloc(do_list_queue_size); + do_list_queue = SMB_MALLOC(do_list_queue_size); if (do_list_queue == 0) { d_printf("malloc fail for size %d\n", (int)do_list_queue_size); @@ -425,7 +425,7 @@ 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 = SMB_REALLOC(do_list_queue, do_list_queue_size); if (! dlq) { d_printf("failure enlarging do_list_queue to %d bytes\n", (int)do_list_queue_size); @@ -704,7 +704,7 @@ DEBUG(1,("getting file %s of size %.0f as %s ", rname, (double)size, lname)); - if(!(data = (char *)malloc(read_size))) { + if(!(data = (char *)SMB_MALLOC(read_size))) { d_printf("malloc fail for size %d\n", read_size); cli_close(cli, fnum); return 1; @@ -1112,7 +1112,7 @@ DEBUG(1,("putting file %s as %s ",lname, rname)); - buf = (char *)malloc(maxwrite); + buf = (char *)SMB_MALLOC(maxwrite); if (!buf) { d_printf("ERROR: Not enough memory!\n"); return 1; @@ -1325,7 +1325,7 @@ return -1; } } - entry = (struct file_list *) malloc(sizeof (struct file_list)); + entry = SMB_MALLOC_P(struct file_list); if (!entry) { d_printf("Out of memory in file_find\n"); closedir(dir); @@ -2521,7 +2521,7 @@ if ((info->count < MAX_COMPLETIONS - 1) && (strncmp(info->text, f->name, info->len) == 0) && (strcmp(f->name, ".") != 0) && (strcmp(f->name, "..") != 0)) { if ((info->dirmask[0] == 0) && !(f->mode & aDIR)) - info->matches[info->count] = strdup(f->name); + info->matches[info->count] = SMB_STRDUP(f->name); else { pstring tmp; @@ -2532,7 +2532,7 @@ pstrcat(tmp, f->name); if (f->mode & aDIR) pstrcat(tmp, "/"); - info->matches[info->count] = strdup(tmp); + info->matches[info->count] = SMB_STRDUP(tmp); } if (info->matches[info->count] == NULL) return; @@ -2563,7 +2563,7 @@ if (len >= PATH_MAX) return(NULL); - info.matches = (char **)malloc(sizeof(info.matches[0])*MAX_COMPLETIONS); + info.matches = SMB_MALLOC_ARRAY(char *,MAX_COMPLETIONS); if (!info.matches) return NULL; info.matches[0] = NULL; @@ -2584,9 +2584,9 @@ goto cleanup; if (info.count == 2) - info.matches[0] = strdup(info.matches[1]); + info.matches[0] = SMB_STRDUP(info.matches[1]); else { - info.matches[0] = malloc(info.samelen+1); + info.matches[0] = SMB_MALLOC(info.samelen+1); if (!info.matches[0]) goto cleanup; strncpy(info.matches[0], info.matches[1], info.samelen); @@ -2641,14 +2641,14 @@ char **matches; int i, len, samelen, count=1; - matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS); + matches = SMB_MALLOC_ARRAY(char *, MAX_COMPLETIONS); if (!matches) return NULL; matches[0] = NULL; len = strlen(text); for (i=0;commands[i].fn && count < MAX_COMPLETIONS-1;i++) { if (strncmp(text, commands[i].name, len) == 0) { - matches[count] = strdup(commands[i].name); + matches[count] = SMB_STRDUP(commands[i].name); if (!matches[count]) goto cleanup; if (count == 1) @@ -2665,10 +2665,10 @@ case 1: goto cleanup; case 2: - matches[0] = strdup(matches[1]); + matches[0] = SMB_STRDUP(matches[1]); break; default: - matches[0] = malloc(samelen+1); + matches[0] = SMB_MALLOC(samelen+1); if (!matches[0]) goto cleanup; strncpy(matches[0], matches[1], samelen); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/client/clitar.c samba-3.0.9/source/client/clitar.c --- samba-3.0.9-orig/source/client/clitar.c 2004-11-15 21:03:35.000000000 -0600 +++ samba-3.0.9/source/client/clitar.c 2004-12-09 09:00:27.610513721 -0600 @@ -146,7 +146,7 @@ { char *tmp; - tmp = (char *)malloc(size+1); + tmp = (char *)SMB_MALLOC(size+1); if (tmp == NULL) { DEBUG(0, ("Out of memory in string_create_s\n")); @@ -177,7 +177,7 @@ if (l+2 >= NAMSIZ) { /* write a GNU tar style long header */ char *b; - b = (char *)malloc(l+TBLOCK+100); + b = (char *)SMB_MALLOC(l+TBLOCK+100); if (!b) { DEBUG(0,("out of memory\n")); exit(1); @@ -385,7 +385,7 @@ { /* initialize tar buffer */ tbufsiz=blocksize*TBLOCK; - tarbuf=malloc(tbufsiz); /* FIXME: We might not get the buffer */ + tarbuf=SMB_MALLOC(tbufsiz); /* FIXME: We might not get the buffer */ /* reset tar buffer pointer and tar file counter and total dumped */ tp=0; ntarf=0; ttarf=0; @@ -1059,7 +1059,7 @@ /* finfo.size here is the length of the filename as written by the "/./@LongLink" name * header call. */ int namesize = finfo.size + strlen(cur_dir) + 2; - char *longname = malloc(namesize); + char *longname = SMB_MALLOC(namesize); int offset = 0, left = finfo.size; BOOL first = True; @@ -1506,7 +1506,7 @@ while ((! error) && (x_fgets(buf, sizeof(buf)-1, inclusion))) { if (inclusion_buffer == NULL) { inclusion_buffer_size = 1024; - if ((inclusion_buffer = malloc(inclusion_buffer_size)) == NULL) { + if ((inclusion_buffer = SMB_MALLOC(inclusion_buffer_size)) == NULL) { DEBUG(0,("failure allocating buffer to read inclusion file\n")); error = 1; break; @@ -1520,7 +1520,7 @@ if ((strlen(buf) + 1 + inclusion_buffer_sofar) >= inclusion_buffer_size) { char *ib; inclusion_buffer_size *= 2; - ib = Realloc(inclusion_buffer,inclusion_buffer_size); + ib = SMB_REALLOC(inclusion_buffer,inclusion_buffer_size); if (! ib) { DEBUG(0,("failure enlarging inclusion buffer to %d bytes\n", inclusion_buffer_size)); @@ -1539,7 +1539,7 @@ if (! error) { /* Allocate an array of clipn + 1 char*'s for cliplist */ - cliplist = malloc((clipn + 1) * sizeof(char *)); + cliplist = SMB_MALLOC_ARRAY(char *, clipn + 1); if (cliplist == NULL) { DEBUG(0,("failure allocating memory for cliplist\n")); error = 1; @@ -1550,7 +1550,7 @@ /* set current item to NULL so array will be null-terminated even if * malloc fails below. */ cliplist[i] = NULL; - if ((tmpstr = (char *)malloc(strlen(p)+1)) == NULL) { + if ((tmpstr = (char *)SMB_MALLOC(strlen(p)+1)) == NULL) { DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", i)); error = 1; } else { @@ -1720,7 +1720,7 @@ clipn=argc-Optind-1; clipcount = clipn; - if ((tmplist=malloc(clipn*sizeof(char *))) == NULL) { + if ((tmplist=SMB_MALLOC_ARRAY(char *,clipn)) == NULL) { DEBUG(0, ("Could not allocate space to process cliplist, count = %i\n", clipn)); return 0; } @@ -1729,7 +1729,7 @@ DEBUG(5, ("Processing an item, %s\n", cliplist[clipcount])); - if ((tmpstr = (char *)malloc(strlen(cliplist[clipcount])+1)) == NULL) { + if ((tmpstr = (char *)SMB_MALLOC(strlen(cliplist[clipcount])+1)) == NULL) { DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", clipcount)); return 0; } @@ -1751,7 +1751,7 @@ #ifdef HAVE_REGEX_H int errcode; - if ((preg = (regex_t *)malloc(65536)) == NULL) { + if ((preg = (regex_t *)SMB_MALLOC(65536)) == NULL) { DEBUG(0, ("Could not allocate buffer for regular expression search\n")); return; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/groupdb/mapping.c samba-3.0.9/source/groupdb/mapping.c --- samba-3.0.9-orig/source/groupdb/mapping.c 2004-11-15 21:03:17.000000000 -0600 +++ samba-3.0.9/source/groupdb/mapping.c 2004-12-09 09:00:27.131632696 -0600 @@ -469,7 +469,7 @@ decode_sid_name_use(group_type, map.sid_name_use); DEBUG(11,("enum_group_mapping: returning group %s of type %s\n", map.nt_name ,group_type)); - mapt=(GROUP_MAP *)Realloc((*rmap), (entries+1)*sizeof(GROUP_MAP)); + mapt= SMB_REALLOC_ARRAY((*rmap), GROUP_MAP, entries+1); if (!mapt) { DEBUG(0,("enum_group_mapping: Unable to enlarge group map!\n")); SAFE_FREE(*rmap); @@ -599,7 +599,7 @@ asprintf(&new_memberstring, "%s %s", (char *)(dbuf.dptr), string_sid); } else { - new_memberstring = strdup(string_sid); + new_memberstring = SMB_STRDUP(string_sid); } if (new_memberstring == NULL) @@ -739,7 +739,7 @@ return tdb_delete(tdb, kbuf) == 0 ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; - member_string = strdup(""); + member_string = SMB_STRDUP(""); if (member_string == NULL) { SAFE_FREE(sids); @@ -1278,7 +1278,7 @@ if (*num_aliases > max_entries) *num_aliases = max_entries; - *info = malloc(sizeof(struct acct_info) * (*num_aliases)); + *info = SMB_MALLOC_ARRAY(struct acct_info, *num_aliases); for (i=0; i<*num_aliases; i++) { fstrcpy((*info)[i].acct_name, map[i+start_idx].nt_name); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/include/smb.h samba-3.0.9/source/include/smb.h --- samba-3.0.9-orig/source/include/smb.h 2004-11-15 21:03:30.000000000 -0600 +++ samba-3.0.9/source/include/smb.h 2004-12-09 09:00:27.505539801 -0600 @@ -53,9 +53,6 @@ #define _BOOL /* So we don't typedef BOOL again in vfs.h */ #endif -/* limiting size of ipc replies */ -#define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024)) - #define SIZEOFWORD 2 #ifndef DEF_CREATE_MASK @@ -1656,7 +1653,7 @@ #define SAFE_NETBIOS_CHARS ". -_" /* generic iconv conversion structure */ -typedef struct { +typedef struct _smb_iconv_t { size_t (*direct)(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); size_t (*pull)(void *cd, const char **inbuf, size_t *inbytesleft, diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/include/smb_macros.h samba-3.0.9/source/include/smb_macros.h --- samba-3.0.9-orig/source/include/smb_macros.h 2004-11-15 21:03:30.000000000 -0600 +++ samba-3.0.9/source/include/smb_macros.h 2004-12-09 09:00:27.508539056 -0600 @@ -261,4 +261,92 @@ #define IS_DC (lp_server_role()==ROLE_DOMAIN_PDC || lp_server_role()==ROLE_DOMAIN_BDC) +/***************************************************************************** + Safe allocation macros. +*****************************************************************************/ + +#define SMB_MALLOC_ARRAY(type,count) (type *)malloc_array(sizeof(type),(count)) +#define SMB_REALLOC(p,s) Realloc((p),(s)) +#define SMB_REALLOC_ARRAY(p,type,count) (type *)realloc_array((p),sizeof(type),(count)) +#define SMB_CALLOC_ARRAY(type,count) (type *)calloc_array(sizeof(type),(count)) +#define SMB_XMALLOC_P(type) (type *)smb_xmalloc_array(sizeof(type),1) +#define SMB_XMALLOC_ARRAY(type,count) (type *)smb_xmalloc_array(sizeof(type),(count)) + +/* limiting size of ipc replies */ +#define SMB_REALLOC_LIMIT(ptr,size) SMB_REALLOC(ptr,MAX((size),4*1024)) + +/* #define PARANOID_MALLOC_CHECKER 1 */ + +#if defined(PARANOID_MALLOC_CHECKER) + +#define TALLOC(ctx, size) talloc_((ctx),(size)) +#define TALLOC_P(ctx, type) (type *)talloc_((ctx),sizeof(type)) +#define TALLOC_ARRAY(ctx, type, count) (type *)talloc_array_((ctx),sizeof(type),(count)) +#define TALLOC_MEMDUP(ctx, ptr, size) talloc_memdup_((ctx),(ptr),(size)) +#define TALLOC_ZERO(ctx, size) talloc_zero_((ctx),(size)) +#define TALLOC_ZERO_P(ctx, type) (type *)talloc_zero_((ctx),sizeof(type)) +#define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)talloc_zero_array_((ctx),sizeof(type),(count)) +#define TALLOC_REALLOC(ctx, ptr, count) talloc_realloc_((ctx),(ptr),(count)) +#define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)talloc_realloc_array_((ctx),(ptr),sizeof(type),(count)) + +#define PRS_ALLOC_MEM(ps, type, count) (type *)prs_alloc_mem_((ps),sizeof(type),(count)) + +/* Get medieval on our ass about malloc.... */ + +/* Restrictions on malloc/realloc/calloc. */ +#ifdef malloc +#undef malloc +#endif +#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY + +#ifdef realloc +#undef realloc +#endif +#define realloc(p,s) __ERROR_DONT_USE_REALLOC_DIRECTLY + +#ifdef calloc +#undef calloc +#endif +#define calloc(n,s) __ERROR_DONT_USE_CALLOC_DIRECTLY + +#ifdef strndup +#undef strndup +#endif +#define strndup(s,n) __ERROR_DONT_USE_STRNDUP_DIRECTLY + +#ifdef strdup +#undef strdup +#endif +#define strdup(s) __ERROR_DONT_USE_STRDUP_DIRECTLY + +#define SMB_MALLOC(s) malloc_(s) +#define SMB_MALLOC_P(type) (type *)malloc_(sizeof(type)) + +#define SMB_STRDUP(s) smb_xstrdup(s) +#define SMB_STRNDUP(s,n) smb_xstrndup(s,n) + +#else + +#define TALLOC(ctx, size) talloc((ctx),(size)) +#define TALLOC_P(ctx, type) (type *)talloc((ctx),sizeof(type)) +#define TALLOC_ARRAY(ctx, type, count) (type *)talloc_array((ctx),sizeof(type),(count)) +#define TALLOC_MEMDUP(ctx, ptr, size) talloc_memdup((ctx),(ptr),(size)) +#define TALLOC_ZERO(ctx, size) talloc_zero((ctx),(size)) +#define TALLOC_ZERO_P(ctx, type) (type *)talloc_zero((ctx),sizeof(type)) +#define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)talloc_zero_array((ctx),sizeof(type),(count)) +#define TALLOC_REALLOC(ctx, ptr, count) talloc_realloc((ctx),(ptr),(count)) +#define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)talloc_realloc_array((ctx),(ptr),sizeof(type),(count)) + +#define PRS_ALLOC_MEM(ps, type, count) (type *)prs_alloc_mem((ps),sizeof(type),(count)) + +/* Regular malloc code. */ + +#define SMB_MALLOC(s) malloc(s) +#define SMB_MALLOC_P(type) (type *)malloc(sizeof(type)) + +#define SMB_STRDUP(s) strdup(s) +#define SMB_STRNDUP(s,n) strndup(s,n) + +#endif + #endif /* _SMB_MACROS_H */ diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/intl/lang_tdb.c samba-3.0.9/source/intl/lang_tdb.c --- samba-3.0.9-orig/source/intl/lang_tdb.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/intl/lang_tdb.c 2004-12-09 09:00:27.250603139 -0600 @@ -148,7 +148,7 @@ strerror(errno))); goto done; } - current_lang = strdup(lang); + current_lang = SMB_STRDUP(lang); result = True; goto done; } @@ -160,7 +160,7 @@ tdb_store_int32(tdb, "/LOADTIME/", (int)time(NULL)); } - current_lang = strdup(lang); + current_lang = SMB_STRDUP(lang); result = True; done: @@ -194,7 +194,7 @@ count++; } - if (!(msgid_quoted = malloc(strlen(msgid) + count + 1))) + if (!(msgid_quoted = SMB_MALLOC(strlen(msgid) + count + 1))) return msgid; /* string_sub() is unsuitable here as it replaces some punctuation @@ -221,7 +221,7 @@ /* if the message isn't found then we still need to return a pointer that can be freed. Pity. */ if (!data.dptr) - return strdup(msgid); + return SMB_STRDUP(msgid); return (const char *)data.dptr; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/access.c samba-3.0.9/source/lib/access.c --- samba-3.0.9-orig/source/lib/access.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/access.c 2004-12-09 09:00:27.189618290 -0600 @@ -86,7 +86,7 @@ DEBUG(0,("Unable to get default yp domain.\n")); return False; } - if (!(hostname = strdup(s))) { + if (!(hostname = SMB_STRDUP(s))) { DEBUG(1,("out of memory for strdup!\n")); return False; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/account_pol.c samba-3.0.9/source/lib/account_pol.c --- samba-3.0.9-orig/source/lib/account_pol.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/lib/account_pol.c 2004-12-09 09:00:27.229608355 -0600 @@ -88,7 +88,7 @@ len += strlen(account_policy_names[i].string) + 1; } len++; - nl = malloc(len); + nl = SMB_MALLOC(len); if (!nl) { return NULL; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/adt_tree.c samba-3.0.9/source/lib/adt_tree.c --- samba-3.0.9-orig/source/lib/adt_tree.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/adt_tree.c 2004-12-09 09:00:27.182620028 -0600 @@ -59,7 +59,7 @@ { SORTED_TREE *tree = NULL; - if ( !(tree = (SORTED_TREE*)malloc( sizeof(SORTED_TREE) )) ) + if ( !(tree = SMB_MALLOC_P(SORTED_TREE)) ) return NULL; ZERO_STRUCTP( tree ); @@ -67,7 +67,7 @@ tree->compare = cmp_fn; tree->free_func = free_fn; - if ( !(tree->root = (TREE_NODE*)malloc( sizeof(TREE_NODE) )) ) { + if ( !(tree->root = SMB_MALLOC_P(TREE_NODE)) ) { SAFE_FREE( tree ); return NULL; } @@ -126,15 +126,15 @@ TREE_NODE **siblings; int i; - if ( !(infant = (TREE_NODE*)malloc( sizeof(TREE_NODE) )) ) + if ( !(infant = SMB_MALLOC_P(TREE_NODE)) ) return NULL; ZERO_STRUCTP( infant ); - infant->key = strdup( key ); + infant->key = SMB_STRDUP( key ); infant->parent = node; - siblings = Realloc( node->children, sizeof(TREE_NODE*)*(node->num_children+1) ); + siblings = SMB_REALLOC_ARRAY( node->children, TREE_NODE *, node->num_children+1 ); if ( siblings ) node->children = siblings; @@ -260,7 +260,7 @@ /* move past the first '/' */ path++; - path2 = strdup( path ); + path2 = SMB_STRDUP( path ); if ( !path2 ) { DEBUG(0,("sorted_tree_add: strdup() failed on string [%s]!?!?!\n", path)); return False; @@ -405,9 +405,9 @@ /* make a copy to play with */ if ( *key == '/' ) - keystr = strdup( key+1 ); + keystr = SMB_STRDUP( key+1 ); else - keystr = strdup( key ); + keystr = SMB_STRDUP( key ); if ( !keystr ) { DEBUG(0,("sorted_tree_find: strdup() failed on string [%s]!?!?!\n", key)); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/bitmap.c samba-3.0.9/source/lib/bitmap.c --- samba-3.0.9-orig/source/lib/bitmap.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/bitmap.c 2004-12-09 09:00:27.196616551 -0600 @@ -30,12 +30,12 @@ { struct bitmap *bm; - bm = (struct bitmap *)malloc(sizeof(*bm)); + bm = SMB_MALLOC_P(struct bitmap); if (!bm) return NULL; bm->n = n; - bm->b = (uint32 *)malloc(sizeof(bm->b[0])*(n+31)/32); + bm->b = SMB_MALLOC_ARRAY(uint32, (n+31)/32); if (!bm->b) { SAFE_FREE(bm); return NULL; @@ -68,12 +68,12 @@ if (!mem_ctx) return NULL; - bm = (struct bitmap *)talloc(mem_ctx, sizeof(*bm)); + bm = TALLOC_P(mem_ctx, struct bitmap); if (!bm) return NULL; bm->n = n; - bm->b = (uint32 *)talloc(mem_ctx, sizeof(bm->b[0])*(n+31)/32); + bm->b = TALLOC_ARRAY(mem_ctx, uint32, (n+31)/32); if (!bm->b) { return NULL; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/charcnv.c samba-3.0.9/source/lib/charcnv.c --- samba-3.0.9-orig/source/lib/charcnv.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/lib/charcnv.c 2004-12-09 09:00:27.248603635 -0600 @@ -538,9 +538,9 @@ } if (ctx) - ob = (char *)talloc_realloc(ctx, ob, destlen); + ob = (char *)TALLOC_REALLOC(ctx, ob, destlen); else - ob = (char *)Realloc(ob, destlen); + ob = (char *)SMB_REALLOC(ob, destlen); if (!ob) { DEBUG(0, ("convert_string_allocate: realloc failed!\n")); @@ -588,9 +588,9 @@ destlen = destlen - o_len; if (ctx) - *dest = (char *)talloc_realloc(ctx,ob,destlen); + *dest = (char *)TALLOC_REALLOC(ctx,ob,destlen); else - *dest = (char *)Realloc(ob,destlen); + *dest = (char *)SMB_REALLOC(ob,destlen); if (destlen && !*dest) { DEBUG(0, ("convert_string_allocate: out of memory!\n")); if (!ctx) @@ -763,7 +763,7 @@ } } - return strdup(out_buffer); + return SMB_STRDUP(out_buffer); } size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/data_blob.c samba-3.0.9/source/lib/data_blob.c --- samba-3.0.9-orig/source/lib/data_blob.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/data_blob.c 2004-12-09 09:00:27.170623009 -0600 @@ -47,7 +47,7 @@ if (p) { ret.data = smb_xmemdup(p, length); } else { - ret.data = smb_xmalloc(length); + ret.data = SMB_XMALLOC_ARRAY(char, length); } ret.length = length; ret.free = free_data_blob; @@ -67,11 +67,11 @@ } if (p) { - ret.data = talloc_memdup(mem_ctx, p, length); + ret.data = TALLOC_MEMDUP(mem_ctx, p, length); if (ret.data == NULL) smb_panic("data_blob_talloc: talloc_memdup failed.\n"); } else { - ret.data = talloc(mem_ctx, length); + ret.data = TALLOC(mem_ctx, length); if (ret.data == NULL) smb_panic("data_blob_talloc: talloc failed.\n"); } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/debug.c samba-3.0.9/source/lib/debug.c --- samba-3.0.9-orig/source/lib/debug.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/debug.c 2004-12-09 09:00:27.180620525 -0600 @@ -192,7 +192,7 @@ if (DEBUGLEVEL_CLASS == &debug_all_class_hack) return NULL; - list = calloc(debug_num_classes + 1, sizeof(char *)); + list = SMB_CALLOC_ARRAY(char *, debug_num_classes + 1); if (!list) return NULL; @@ -210,7 +210,7 @@ } /* create single string list - add space for newline */ - b = buf = malloc(dim+1); + b = buf = SMB_MALLOC(dim+1); if (!buf) { err = True; goto done; @@ -292,7 +292,7 @@ /* Initial loading... */ new_ptr = NULL; } - new_ptr = Realloc(new_ptr, sizeof(int) * (debug_num_classes + 1)); + new_ptr = SMB_REALLOC_ARRAY(new_ptr, int, debug_num_classes + 1); if (!new_ptr) return -1; DEBUGLEVEL_CLASS = new_ptr; @@ -309,19 +309,18 @@ if (new_ptr == &debug_all_class_isset_hack) { new_ptr = NULL; } - new_ptr = Realloc(new_ptr, sizeof(BOOL) * (debug_num_classes + 1)); + new_ptr = SMB_REALLOC_ARRAY(new_ptr, BOOL, debug_num_classes + 1); if (!new_ptr) return -1; DEBUGLEVEL_CLASS_ISSET = new_ptr; DEBUGLEVEL_CLASS_ISSET[ndx] = False; - new_ptr = Realloc(classname_table, - sizeof(char *) * (debug_num_classes + 1)); + new_ptr = SMB_REALLOC_ARRAY(classname_table, char *, debug_num_classes + 1); if (!new_ptr) return -1; classname_table = new_ptr; - classname_table[ndx] = strdup(classname); + classname_table[ndx] = SMB_STRDUP(classname); if (! classname_table[ndx]) return -1; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/dprintf.c samba-3.0.9/source/lib/dprintf.c --- samba-3.0.9-orig/source/lib/dprintf.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/lib/dprintf.c 2004-12-09 09:00:27.228608603 -0600 @@ -54,7 +54,7 @@ charset, but beware of it growing */ maxlen = ret*2; again: - p2 = malloc(maxlen); + p2 = SMB_MALLOC(maxlen); if (!p2) { SAFE_FREE(p); return -1; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/gencache.c samba-3.0.9/source/lib/gencache.c --- samba-3.0.9-orig/source/lib/gencache.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/gencache.c 2004-12-09 09:00:27.204614564 -0600 @@ -117,9 +117,9 @@ if (!valstr) return False; - keybuf.dptr = strdup(keystr); + keybuf.dptr = SMB_STRDUP(keystr); keybuf.dsize = strlen(keystr)+1; - databuf.dptr = strdup(valstr); + databuf.dptr = SMB_STRDUP(valstr); databuf.dsize = strlen(valstr)+1; DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout =" " %s (%d seconds %s)\n", keybuf.dptr, value,ctime(&timeout), @@ -170,9 +170,9 @@ = %s\n", keystr, old_valstr, ctime(&old_timeout))); asprintf(&datastr, CACHE_DATA_FMT, (int)timeout, valstr); - keybuf.dptr = strdup(keystr); + keybuf.dptr = SMB_STRDUP(keystr); keybuf.dsize = strlen(keystr)+1; - databuf.dptr = strdup(datastr); + databuf.dptr = SMB_STRDUP(datastr); databuf.dsize = strlen(datastr)+1; DEBUGADD(10, ("New value = %s, new timeout = %s (%d seconds %s)", valstr, ctime(&timeout), (int)(timeout - time(NULL)), @@ -209,7 +209,7 @@ if (!gencache_init()) return False; - keybuf.dptr = strdup(keystr); + keybuf.dptr = SMB_STRDUP(keystr); keybuf.dsize = strlen(keystr)+1; DEBUG(10, ("Deleting cache entry (key = %s)\n", keystr)); ret = tdb_delete(cache, keybuf); @@ -242,18 +242,17 @@ if (!gencache_init()) return False; - keybuf.dptr = strdup(keystr); + keybuf.dptr = SMB_STRDUP(keystr); keybuf.dsize = strlen(keystr)+1; databuf = tdb_fetch(cache, keybuf); SAFE_FREE(keybuf.dptr); if (databuf.dptr && databuf.dsize > TIMEOUT_LEN) { - char* entry_buf = strndup(databuf.dptr, databuf.dsize); + char* entry_buf = SMB_STRNDUP(databuf.dptr, databuf.dsize); char *v; time_t t; - v = (char*)malloc(sizeof(char) * - (databuf.dsize - TIMEOUT_LEN)); + v = SMB_MALLOC(databuf.dsize - TIMEOUT_LEN); SAFE_FREE(databuf.dptr); sscanf(entry_buf, CACHE_DATA_FMT, (int*)&t, v); @@ -320,7 +319,7 @@ while (node) { /* ensure null termination of the key string */ - keystr = strndup(node->node_key.dptr, node->node_key.dsize); + keystr = SMB_STRNDUP(node->node_key.dptr, node->node_key.dsize); /* * We don't use gencache_get function, because we need to iterate through @@ -333,9 +332,9 @@ node = node->next; continue; } - entry = strndup(databuf.dptr, databuf.dsize); + entry = SMB_STRNDUP(databuf.dptr, databuf.dsize); SAFE_FREE(databuf.dptr); - valstr = (char*)malloc(sizeof(char) * (databuf.dsize - TIMEOUT_LEN)); + valstr = SMB_MALLOC(databuf.dsize - TIMEOUT_LEN); sscanf(entry, CACHE_DATA_FMT, (int*)(&timeout), valstr); DEBUG(10, ("Calling function with arguments (key = %s, value = %s, timeout = %s)\n", diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/iconv.c samba-3.0.9/source/lib/iconv.c --- samba-3.0.9-orig/source/lib/iconv.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/iconv.c 2004-12-09 09:00:27.213612329 -0600 @@ -209,15 +209,15 @@ from = charsets; to = charsets; - ret = (smb_iconv_t)malloc(sizeof(*ret)); + ret = SMB_MALLOC_P(struct _smb_iconv_t); if (!ret) { errno = ENOMEM; return (smb_iconv_t)-1; } - memset(ret, 0, sizeof(*ret)); + memset(ret, 0, sizeof(struct _smb_iconv_t)); - ret->from_name = strdup(fromcode); - ret->to_name = strdup(tocode); + ret->from_name = SMB_STRDUP(fromcode); + ret->to_name = SMB_STRDUP(tocode); /* check for the simplest null conversion */ if (strcasecmp(fromcode, tocode) == 0) { diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/interface.c samba-3.0.9/source/lib/interface.c --- samba-3.0.9-orig/source/lib/interface.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/interface.c 2004-12-09 09:00:27.169623257 -0600 @@ -65,7 +65,7 @@ return; } - iface = (struct interface *)malloc(sizeof(*iface)); + iface = SMB_MALLOC_P(struct interface); if (!iface) return; ZERO_STRUCTPN(iface); @@ -207,7 +207,7 @@ if (ptr) { while (*ptr) { - char *ptr_cpy = strdup(*ptr); + char *ptr_cpy = SMB_STRDUP(*ptr); if (ptr_cpy) { interpret_interface(ptr_cpy); free(ptr_cpy); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/ldap_escape.c samba-3.0.9/source/lib/ldap_escape.c --- samba-3.0.9-orig/source/lib/ldap_escape.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/ldap_escape.c 2004-12-09 09:00:27.205614316 -0600 @@ -36,7 +36,7 @@ char *escape_ldap_string_alloc(const char *s) { size_t len = strlen(s)+1; - char *output = malloc(len); + char *output = SMB_MALLOC(len); char *output_tmp; const char *sub; int i = 0; @@ -65,7 +65,7 @@ if (sub) { len = len + 3; - output_tmp = realloc(output, len); + output_tmp = SMB_REALLOC(output, len); if (!output_tmp) { SAFE_FREE(output); return NULL; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/messages.c samba-3.0.9/source/lib/messages.c --- samba-3.0.9-orig/source/lib/messages.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/lib/messages.c 2004-12-09 09:00:27.234607113 -0600 @@ -190,7 +190,7 @@ kbuf = message_key_pid(pid); - dbuf.dptr = (void *)malloc(len + sizeof(rec)); + dbuf.dptr = (void *)SMB_MALLOC(len + sizeof(rec)); if (!dbuf.dptr) return False; @@ -468,7 +468,7 @@ { struct dispatch_fns *dfn; - dfn = (struct dispatch_fns *)malloc(sizeof(*dfn)); + dfn = SMB_MALLOC_P(struct dispatch_fns); if (dfn != NULL) { diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/module.c samba-3.0.9/source/lib/module.c --- samba-3.0.9-orig/source/lib/module.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/module.c 2004-12-09 09:00:27.202615061 -0600 @@ -172,7 +172,7 @@ return SMB_EVENT_ID_INVALID; } - event = (struct smb_idle_list_ent *)malloc(sizeof(struct smb_idle_list_ent)); + event = SMB_MALLOC_P(struct smb_idle_list_ent); if (!event) { DEBUG(0,("malloc() failed!\n")); return SMB_EVENT_ID_INVALID; @@ -254,7 +254,7 @@ return SMB_EVENT_ID_INVALID; } - event = (struct smb_exit_list_ent *)malloc(sizeof(struct smb_exit_list_ent)); + event = SMB_MALLOC_P(struct smb_exit_list_ent); if (!event) { DEBUG(0,("malloc() failed!\n")); return SMB_EVENT_ID_INVALID; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/ms_fnmatch.c samba-3.0.9/source/lib/ms_fnmatch.c --- samba-3.0.9-orig/source/lib/ms_fnmatch.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/ms_fnmatch.c 2004-12-09 09:00:27.197616303 -0600 @@ -195,7 +195,7 @@ } if (count != 0) { - max_n = calloc(sizeof(struct max_n), count); + max_n = SMB_CALLOC_ARRAY(struct max_n, count); if (!max_n) { return -1; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/privileges.c samba-3.0.9/source/lib/privileges.c --- samba-3.0.9-orig/source/lib/privileges.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/privileges.c 2004-12-09 09:00:27.208613571 -0600 @@ -75,7 +75,7 @@ if ( !old_la ) return NT_STATUS_OK; - *new_la = (LUID_ATTR *)talloc(mem_ctx, sizeof(LUID_ATTR)); + *new_la = TALLOC_P(mem_ctx, LUID_ATTR); ALLOC_CHECK(new_la, ret, done, "dupalloc_luid_attr"); (*new_la)->luid.high = old_la->luid.high; @@ -97,7 +97,7 @@ TALLOC_CTX *mem_ctx = talloc_init("privilege set"); ALLOC_CHECK(mem_ctx, ret, done, "init_privilege"); - *priv_set = talloc_zero(mem_ctx, sizeof(PRIVILEGE_SET)); + *priv_set = TALLOC_ZERO_P(mem_ctx, PRIVILEGE_SET); ALLOC_CHECK(*priv_set, ret, done, "init_privilege"); (*priv_set)->mem_ctx = mem_ctx; @@ -112,7 +112,7 @@ { NTSTATUS ret; - *priv_set = talloc_zero(mem_ctx, sizeof(PRIVILEGE_SET)); + *priv_set = TALLOC_ZERO_P(mem_ctx, PRIVILEGE_SET); ALLOC_CHECK(*priv_set, ret, done, "init_privilege"); (*priv_set)->mem_ctx = mem_ctx; @@ -154,7 +154,7 @@ /* we can allocate memory to add the new privilege */ - new_set = (LUID_ATTR *)talloc_realloc(priv_set->mem_ctx, priv_set->set, (priv_set->count + 1) * (sizeof(LUID_ATTR))); + new_set = TALLOC_REALLOC_ARRAY(priv_set->mem_ctx, priv_set->set, LUID_ATTR, priv_set->count + 1); ALLOC_CHECK(new_set, ret, done, "add_privilege"); new_set[priv_set->count].luid.high = set.luid.high; @@ -269,7 +269,7 @@ old_set = priv_set->set; - new_set = (LUID_ATTR *)talloc(priv_set->mem_ctx, (priv_set->count - 1) * (sizeof(LUID_ATTR))); + new_set = TALLOC_ARRAY(priv_set->mem_ctx, LUID_ATTR, priv_set->count - 1); ALLOC_CHECK(new_set, ret, done, "remove_privilege"); for (i=0, j=0; i < priv_set->count; i++) { @@ -329,7 +329,7 @@ old_set = priv_set->set; - new_set = (LUID_ATTR *)talloc(new_priv_set->mem_ctx, (priv_set->count - 1) * (sizeof(LUID_ATTR))); + new_set = TALLOC_ARRAY(new_priv_set->mem_ctx, LUID_ATTR, priv_set->count - 1); ALLOC_CHECK(new_set, ret, done, "dup_priv_set"); for (i=0; i < priv_set->count; i++) { diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/secace.c samba-3.0.9/source/lib/secace.c --- samba-3.0.9-orig/source/lib/secace.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/secace.c 2004-12-09 09:00:27.222610093 -0600 @@ -80,7 +80,7 @@ *num += 1; - if((new[0] = (SEC_ACE *) talloc_zero(ctx, (*num) * sizeof(SEC_ACE))) == 0) + if((new[0] = TALLOC_ZERO_ARRAY(ctx, SEC_ACE, *num )) == 0) return NT_STATUS_NO_MEMORY; for (i = 0; i < *num - 1; i ++) @@ -124,7 +124,7 @@ if (!ctx || !new || !old || !sid || !num) return NT_STATUS_INVALID_PARAMETER; - if((new[0] = (SEC_ACE *) talloc_zero(ctx, (*num) * sizeof(SEC_ACE))) == 0) + if((new[0] = TALLOC_ZERO_ARRAY(ctx, SEC_ACE, *num )) == 0) return NT_STATUS_NO_MEMORY; for (i = 0; i < *num; i ++) { diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/secacl.c samba-3.0.9/source/lib/secacl.c --- samba-3.0.9-orig/source/lib/secacl.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/secacl.c 2004-12-09 09:00:27.184619532 -0600 @@ -32,7 +32,7 @@ SEC_ACL *dst; int i; - if((dst = (SEC_ACL *)talloc_zero(ctx,sizeof(SEC_ACL))) == NULL) + if((dst = TALLOC_ZERO_P(ctx,SEC_ACL)) == NULL) return NULL; dst->revision = revision; @@ -46,7 +46,7 @@ positive number. */ if ((num_aces) && - ((dst->ace = (SEC_ACE *)talloc(ctx, sizeof(SEC_ACE) * num_aces)) + ((dst->ace = TALLOC_ARRAY(ctx, SEC_ACE, num_aces)) == NULL)) { return NULL; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/secdesc.c samba-3.0.9/source/lib/secdesc.c --- samba-3.0.9-orig/source/lib/secdesc.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/secdesc.c 2004-12-09 09:00:27.195616800 -0600 @@ -187,7 +187,7 @@ *sd_size = 0; - if(( dst = (SEC_DESC *)talloc_zero(ctx, sizeof(SEC_DESC))) == NULL) + if(( dst = TALLOC_ZERO_P(ctx, SEC_DESC)) == NULL) return NULL; dst->revision = revision; @@ -284,7 +284,7 @@ { SEC_DESC_BUF *dst; - if((dst = (SEC_DESC_BUF *)talloc_zero(ctx, sizeof(SEC_DESC_BUF))) == NULL) + if((dst = TALLOC_ZERO_P(ctx, SEC_DESC_BUF)) == NULL) return NULL; /* max buffer size (allocated size) */ @@ -417,7 +417,7 @@ the_acl = parent_ctr->dacl; - if (!(new_ace_list = talloc(ctx, sizeof(SEC_ACE) * the_acl->num_aces))) + if (!(new_ace_list = TALLOC_ARRAY(ctx, SEC_ACE, the_acl->num_aces))) return NULL; for (i = 0; the_acl && i < the_acl->num_aces; i++) { diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/server_mutex.c samba-3.0.9/source/lib/server_mutex.c --- samba-3.0.9-orig/source/lib/server_mutex.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/server_mutex.c 2004-12-09 09:00:27.183619780 -0600 @@ -33,7 +33,7 @@ BOOL grab_server_mutex(const char *name) { - mutex_server_name = strdup(name); + mutex_server_name = SMB_STRDUP(name); if (!mutex_server_name) { DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name)); return False; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/smbldap.c samba-3.0.9/source/lib/smbldap.c --- samba-3.0.9-orig/source/lib/smbldap.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/lib/smbldap.c 2004-12-09 09:00:27.245604380 -0600 @@ -239,7 +239,7 @@ i++; i++; - names = (char**)malloc( sizeof(char*)*i ); + names = SMB_MALLOC_ARRAY( char*, i ); if ( !names ) { DEBUG(0,("get_attr_list: out of memory\n")); return NULL; @@ -247,7 +247,7 @@ i = 0; while ( table[i].attrib != LDAP_ATTR_LIST_END ) { - names[i] = strdup( table[i].name ); + names[i] = SMB_STRDUP( table[i].name ); i++; } names[i] = NULL; @@ -295,7 +295,7 @@ if (!size) { /* Upgrade 2.2 style entry */ char *p; - char* old_style_key = strdup(*dn); + char* old_style_key = SMB_STRDUP(*dn); char *data; fstring old_style_pw; @@ -408,7 +408,7 @@ #endif if (mods == NULL) { - mods = (LDAPMod **) malloc(sizeof(LDAPMod *)); + mods = SMB_MALLOC_P(LDAPMod *); if (mods == NULL) { DEBUG(0, ("make_a_mod: out of memory!\n")); return; @@ -422,19 +422,19 @@ } if (mods[i] == NULL) { - mods = (LDAPMod **) Realloc (mods, (i + 2) * sizeof (LDAPMod *)); + mods = SMB_REALLOC_ARRAY (mods, LDAPMod *, i + 2); if (mods == NULL) { DEBUG(0, ("make_a_mod: out of memory!\n")); return; } - mods[i] = (LDAPMod *) malloc(sizeof(LDAPMod)); + mods[i] = SMB_MALLOC_P(LDAPMod); if (mods[i] == NULL) { DEBUG(0, ("make_a_mod: out of memory!\n")); return; } mods[i]->mod_op = modop; mods[i]->mod_values = NULL; - mods[i]->mod_type = strdup(attribute); + mods[i]->mod_type = SMB_STRDUP(attribute); mods[i + 1] = NULL; } @@ -445,8 +445,7 @@ if (mods[i]->mod_values != NULL) { for (; mods[i]->mod_values[j] != NULL; j++); } - mods[i]->mod_values = (char **)Realloc(mods[i]->mod_values, - (j + 2) * sizeof (char *)); + mods[i]->mod_values = SMB_REALLOC_ARRAY(mods[i]->mod_values, char *, j + 2); if (mods[i]->mod_values == NULL) { DEBUG (0, ("make_a_mod: Memory allocation failure!\n")); @@ -574,7 +573,7 @@ return; } - t = smb_xmalloc(sizeof(*t)); + t = SMB_XMALLOC_P(struct smbldap_state_lookup); ZERO_STRUCTP(t); DLIST_ADD_END(smbldap_state_lookup_list, t, tmp); @@ -718,11 +717,11 @@ DEBUG(5,("rebind_proc_with_state: Rebinding as \"%s\"\n", ldap_state->bind_dn)); - *whop = strdup(ldap_state->bind_dn); + *whop = SMB_STRDUP(ldap_state->bind_dn); if (!*whop) { return LDAP_NO_MEMORY; } - *credp = strdup(ldap_state->bind_secret); + *credp = SMB_STRDUP(ldap_state->bind_secret); if (!*credp) { SAFE_FREE(*whop); return LDAP_NO_MEMORY; @@ -1207,7 +1206,7 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, const char *location, struct smbldap_state **smbldap_state) { - *smbldap_state = talloc_zero(mem_ctx, sizeof(**smbldap_state)); + *smbldap_state = TALLOC_ZERO_P(mem_ctx, struct smbldap_state); if (!*smbldap_state) { DEBUG(0, ("talloc() failed for ldapsam private_data!\n")); return NT_STATUS_NO_MEMORY; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/substitute.c samba-3.0.9/source/lib/substitute.c --- samba-3.0.9-orig/source/lib/substitute.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/substitute.c 2004-12-09 09:00:27.211612825 -0600 @@ -224,7 +224,7 @@ r = p + 3; copylen = q - r; - envname = (char *)malloc(copylen + 1 + 4); /* reserve space for use later add %$() chars */ + envname = (char *)SMB_MALLOC(copylen + 1 + 4); /* reserve space for use later add %$() chars */ if (envname == NULL) return NULL; strncpy(envname,r,copylen); envname[copylen] = '\0'; @@ -508,7 +508,7 @@ return NULL; } - a_string = strdup(str); + a_string = SMB_STRDUP(str); if (a_string == NULL) { DEBUG(0, ("alloc_sub_specified: Out of memory!\n")); return NULL; @@ -526,7 +526,7 @@ t = realloc_string_sub(t, "%U", r); break; case 'G' : - r = strdup(smb_name); + r = SMB_STRDUP(smb_name); if (r == NULL) goto error; if ((pass = Get_Pwnam(r))!=NULL) { t = realloc_string_sub(t, "%G", gidtoname(pass->pw_gid)); @@ -623,7 +623,7 @@ char *a_string, *ret_string; char *b, *p, *s, *t; - a_string = strdup(input_string); + a_string = SMB_STRDUP(input_string); if (a_string == NULL) { DEBUG(0, ("alloc_sub_specified: Out of memory!\n")); return NULL; @@ -700,7 +700,7 @@ char *a_string, *ret_string; char *b, *p, *s, *t, *h; - a_string = strdup(str); + a_string = SMB_STRDUP(str); if (a_string == NULL) { DEBUG(0, ("alloc_sub_specified: Out of memory!\n")); return NULL; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/system.c samba-3.0.9/source/lib/system.c --- samba-3.0.9-orig/source/lib/system.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/system.c 2004-12-09 09:00:27.226609100 -0600 @@ -1031,7 +1031,7 @@ for( argcl = 1; ptr; ptr = strtok(NULL, " \t")) argcl++; - if((argl = (char **)malloc((argcl + 1) * sizeof(char *))) == NULL) + if((argl = (char **)SMB_MALLOC((argcl + 1) * sizeof(char *))) == NULL) return NULL; /* @@ -1113,7 +1113,7 @@ goto err_exit; } - if((entry = (popen_list *)malloc(sizeof(popen_list))) == NULL) + if((entry = SMB_MALLOC_P(popen_list)) == NULL) goto err_exit; ZERO_STRUCTP(entry); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/system_smbd.c samba-3.0.9/source/lib/system_smbd.c --- samba-3.0.9-orig/source/lib/system_smbd.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/system_smbd.c 2004-12-09 09:00:27.227608851 -0600 @@ -53,7 +53,7 @@ return -1; } - gids_saved = (gid_t *)malloc(sizeof(gid_t) * (ngrp_saved+1)); + gids_saved = SMB_MALLOC_ARRAY(gid_t, ngrp_saved+1); if (!gids_saved) { errno = ENOMEM; return -1; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/talloc.c samba-3.0.9/source/lib/talloc.c --- samba-3.0.9-orig/source/lib/talloc.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/lib/talloc.c 2004-12-09 09:00:27.240605622 -0600 @@ -54,6 +54,8 @@ #include "includes.h" +/* Max allowable allococation - 256mb - 0x10000000 */ +#define MAX_TALLOC_SIZE (1024*1024*256) /** * Start of linked list of all talloc pools. @@ -100,7 +102,7 @@ { TALLOC_CTX *t; - t = (TALLOC_CTX *)malloc(sizeof(TALLOC_CTX)); + t = (TALLOC_CTX *)SMB_MALLOC(sizeof(TALLOC_CTX)); if (t) { t->list = NULL; t->total_alloc_size = 0; @@ -143,16 +145,20 @@ /** Allocate a bit of memory from the specified pool **/ +#if defined(PARANOID_MALLOC_CHECKER) +void *talloc_(TALLOC_CTX *t, size_t size) +#else void *talloc(TALLOC_CTX *t, size_t size) +#endif { void *p; struct talloc_chunk *tc; if (!t || size == 0) return NULL; - p = malloc(size); + p = SMB_MALLOC(size); if (p) { - tc = malloc(sizeof(*tc)); + tc = SMB_MALLOC(sizeof(*tc)); if (tc) { tc->ptr = p; tc->size = size; @@ -167,8 +173,25 @@ return p; } +/** Allocate an array of count elements of size x */ +#if defined(PARANOID_MALLOC_CHECKER) +void *talloc_array_(TALLOC_CTX *ctx, size_t el_size, unsigned int count) +#else +void *talloc_array(TALLOC_CTX *ctx, size_t el_size, unsigned int count) +#endif +{ + if (count >= MAX_TALLOC_SIZE/el_size) { + return NULL; + } + return TALLOC(ctx, el_size * count); +} + /** A talloc version of realloc */ +#if defined(PARANOID_MALLOC_CHECKER) +void *talloc_realloc_(TALLOC_CTX *t, void *ptr, size_t size) +#else void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size) +#endif { struct talloc_chunk *tc; void *new_ptr; @@ -179,11 +202,11 @@ /* realloc(NULL) is equavalent to malloc() */ if (ptr == NULL) - return talloc(t, size); + return TALLOC(t, size); for (tc=t->list; tc; tc=tc->next) { if (tc->ptr == ptr) { - new_ptr = Realloc(ptr, size); + new_ptr = SMB_REALLOC(ptr, size); if (new_ptr) { t->total_alloc_size += (size - tc->size); tc->size = size; @@ -195,6 +218,19 @@ return NULL; } +/** Re-allocate an array of count elements of size x */ +#if defined(PARANOID_MALLOC_CHECKER) +void *talloc_realloc_array_(TALLOC_CTX *ctx, void *ptr, size_t el_size, unsigned int count) +#else +void *talloc_realloc_array(TALLOC_CTX *ctx, void *ptr, size_t el_size, unsigned int count) +#endif +{ + if (count >= MAX_TALLOC_SIZE/el_size) { + return NULL; + } + return TALLOC_REALLOC(ctx, ptr, el_size * count); +} + /** Destroy all the memory allocated inside @p t, but not @p t * itself. */ void talloc_destroy_pool(TALLOC_CTX *t) @@ -246,9 +282,13 @@ /** talloc and zero memory. */ +#if defined(PARANOID_MALLOC_CHECKER) +void *talloc_zero_(TALLOC_CTX *t, size_t size) +#else void *talloc_zero(TALLOC_CTX *t, size_t size) +#endif { - void *p = talloc(t, size); + void *p = TALLOC(t, size); if (p) memset(p, '\0', size); @@ -256,10 +296,32 @@ return p; } +#if defined(PARANOID_MALLOC_CHECKER) +void *talloc_zero_array_(TALLOC_CTX *t, size_t el_size, unsigned int count) +#else +void *talloc_zero_array(TALLOC_CTX *t, size_t el_size, unsigned int count) +#endif +{ +#if defined(PARANOID_MALLOC_CHECKER) + void *p = talloc_array_(t, el_size, count); +#else + void *p = talloc_array(t, el_size, count); +#endif + + if (p) + memset(p, '\0', el_size*count); + + return p; +} + /** memdup with a talloc. */ +#if defined(PARANOID_MALLOC_CHECKER) +void *talloc_memdup_(TALLOC_CTX *t, const void *p, size_t size) +#else void *talloc_memdup(TALLOC_CTX *t, const void *p, size_t size) +#endif { - void *newp = talloc(t,size); + void *newp = TALLOC(t,size); if (newp) memcpy(newp, p, size); @@ -271,7 +333,7 @@ char *talloc_strdup(TALLOC_CTX *t, const char *p) { if (p) - return talloc_memdup(t, p, strlen(p) + 1); + return TALLOC_MEMDUP(t, p, strlen(p) + 1); else return NULL; } @@ -298,7 +360,7 @@ smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p) { if (p) - return talloc_memdup(t, p, (strlen_w(p) + 1) * sizeof(smb_ucs2_t)); + return TALLOC_MEMDUP(t, p, (strlen_w(p) + 1) * sizeof(smb_ucs2_t)); else return NULL; } @@ -329,7 +391,7 @@ len = vsnprintf(NULL, 0, fmt, ap2); - ret = talloc(t, len+1); + ret = TALLOC(t, len+1); if (ret) { VA_COPY(ap2, ap); vsnprintf(ret, len+1, fmt, ap2); @@ -373,7 +435,7 @@ s_len = strlen(s); len = vsnprintf(NULL, 0, fmt, ap2); - s = talloc_realloc(t, s, s_len + len+1); + s = TALLOC_REALLOC(t, s, s_len + len+1); if (!s) return NULL; VA_COPY(ap2, ap); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/time.c samba-3.0.9/source/lib/time.c --- samba-3.0.9-orig/source/lib/time.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/time.c 2004-12-09 09:00:27.188618538 -0600 @@ -190,8 +190,7 @@ time_t low,high; zone = TimeZone(t); - tdt = (struct dst_table *)Realloc(dst_table, - sizeof(dst_table[0])*(i+1)); + tdt = SMB_REALLOC_ARRAY(dst_table, struct dst_table, i+1); if (!tdt) { DEBUG(0,("TimeZoneFaster: out of memory!\n")); SAFE_FREE(dst_table); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/util.c samba-3.0.9/source/lib/util.c --- samba-3.0.9-orig/source/lib/util.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/util.c 2004-12-09 09:00:27.177621270 -0600 @@ -23,6 +23,9 @@ #include "includes.h" +/* Max allowable allococation - 256mb - 0x10000000 */ +#define MAX_ALLOC_SIZE (1024*1024*256) + #if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT)) #ifdef WITH_NISPLUS_HOME #ifdef BROKEN_NISPLUS_INCLUDE_FILES @@ -79,7 +82,7 @@ BOOL set_global_myname(const char *myname) { SAFE_FREE(smb_myname); - smb_myname = strdup(myname); + smb_myname = SMB_STRDUP(myname); if (!smb_myname) return False; strupper_m(smb_myname); @@ -98,7 +101,7 @@ BOOL set_global_myworkgroup(const char *myworkgroup) { SAFE_FREE(smb_myworkgroup); - smb_myworkgroup = strdup(myworkgroup); + smb_myworkgroup = SMB_STRDUP(myworkgroup); if (!smb_myworkgroup) return False; strupper_m(smb_myworkgroup); @@ -117,7 +120,7 @@ BOOL set_global_scope(const char *scope) { SAFE_FREE(smb_scope); - smb_scope = strdup(scope); + smb_scope = SMB_STRDUP(scope); if (!smb_scope) return False; strupper_m(smb_scope); @@ -151,7 +154,7 @@ free_netbios_names_array(); smb_num_netbios_names = number + 1; - smb_my_netbios_names = (char **)malloc( sizeof(char *) * smb_num_netbios_names ); + smb_my_netbios_names = SMB_MALLOC_ARRAY( char *, smb_num_netbios_names ); if (!smb_my_netbios_names) return False; @@ -164,7 +167,7 @@ { SAFE_FREE(smb_my_netbios_names[i]); - smb_my_netbios_names[i] = strdup(name); + smb_my_netbios_names[i] = SMB_STRDUP(name); if (!smb_my_netbios_names[i]) return False; strupper_m(smb_my_netbios_names[i]); @@ -301,7 +304,7 @@ return; } - *gids = Realloc(*gids, (*num+1) * sizeof(gid_t)); + *gids = SMB_REALLOC_ARRAY(*gids, gid_t, *num+1); if (*gids == NULL) return; @@ -351,7 +354,7 @@ while ((p = Atoic(p, &val, ":,")) != NULL && (*p) != ':') { uint32 *tn; - tn = Realloc((*num), ((*count)+1) * sizeof(uint32)); + tn = SMB_REALLOC_ARRAY((*num), uint32, (*count)+1); if (tn == NULL) { SAFE_FREE(*num); return NULL; @@ -727,7 +730,7 @@ size_t num_to_read_thistime; size_t num_written = 0; - if ((buf = malloc(TRANSFER_BUF_SIZE)) == NULL) + if ((buf = SMB_MALLOC(TRANSFER_BUF_SIZE)) == NULL) return -1; while (total < n) { @@ -855,6 +858,82 @@ return(False); } +#if defined(PARANOID_MALLOC_CHECKER) + +/**************************************************************************** + Internal malloc wrapper. Externally visible. +****************************************************************************/ + +void *malloc_(size_t size) +{ +#undef malloc + /* If we don't add an amount here the glibc memset seems to write + one byte over. */ + return malloc(size+16); +#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY +} + +/**************************************************************************** + Internal calloc wrapper. Not externally visible. +****************************************************************************/ + +static void *calloc_(size_t count, size_t size) +{ +#undef calloc + /* If we don't add an amount here the glibc memset seems to write + one byte over. */ + return calloc(count+1, size); +#define calloc(n,s) __ERROR_DONT_USE_CALLOC_DIRECTLY +} + +/**************************************************************************** + Internal realloc wrapper. Not externally visible. +****************************************************************************/ + +static void *realloc_(void *ptr, size_t size) +{ +#undef realloc + /* If we don't add an amount here the glibc memset seems to write + one byte over. */ + return realloc(ptr, size+16); +#define realloc(p,s) __ERROR_DONT_USE_RELLOC_DIRECTLY +} + +#endif /* PARANOID_MALLOC_CHECKER */ + +/**************************************************************************** + Type-safe malloc. +****************************************************************************/ + +void *malloc_array(size_t el_size, unsigned int count) +{ + if (count >= MAX_ALLOC_SIZE/el_size) { + return NULL; + } + +#if defined(PARANOID_MALLOC_CHECKER) + return malloc_(el_size*count); +#else + return malloc(el_size*count); +#endif +} + +/**************************************************************************** + Type-safe calloc. +****************************************************************************/ + +void *calloc_array(size_t size, size_t nmemb) +{ + if (nmemb >= MAX_ALLOC_SIZE/size) { + return NULL; + } +#if defined(PARANOID_MALLOC_CHECKER) + return calloc_(nmemb, size); +#else + return calloc(nmemb, size); +#endif +} + /**************************************************************************** Expand a pointer to be a particular size. ****************************************************************************/ @@ -869,10 +948,17 @@ return NULL; } +#if defined(PARANOID_MALLOC_CHECKER) + if (!p) + ret = (void *)malloc_(size); + else + ret = (void *)realloc_(p,size); +#else if (!p) ret = (void *)malloc(size); else ret = (void *)realloc(p,size); +#endif if (!ret) DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size)); @@ -880,17 +966,16 @@ return(ret); } -void *Realloc_zero(void *ptr, size_t size) -{ - void *tptr = NULL; +/**************************************************************************** + Type-safe realloc. +****************************************************************************/ - tptr = Realloc(ptr, size); - if(tptr == NULL) +void *realloc_array(void *p,size_t el_size, unsigned int count) +{ + if (count >= MAX_ALLOC_SIZE/el_size) { return NULL; - - memset((char *)tptr,'\0',size); - - return tptr; + } + return Realloc(p,el_size*count); } /**************************************************************************** @@ -1595,8 +1680,7 @@ if(num_entries == 0) return; - if(( (*ppname_array) = (name_compare_entry *)malloc( - (num_entries + 1) * sizeof(name_compare_entry))) == NULL) { + if(( (*ppname_array) = SMB_MALLOC_ARRAY(name_compare_entry, num_entries + 1)) == NULL) { DEBUG(0,("set_namearray: malloc fail\n")); return; } @@ -1619,7 +1703,7 @@ break; (*ppname_array)[i].is_wild = ms_has_wild(nameptr); - if(((*ppname_array)[i].name = strdup(nameptr)) == NULL) { + if(((*ppname_array)[i].name = SMB_STRDUP(nameptr)) == NULL) { DEBUG(0,("set_namearray: malloc fail (1)\n")); return; } @@ -2115,14 +2199,18 @@ malloc that aborts with smb_panic on fail or zero size. *****************************************************************/ -void *smb_xmalloc(size_t size) +void *smb_xmalloc_array(size_t size, unsigned int count) { void *p; if (size == 0) - smb_panic("smb_xmalloc: called with zero size.\n"); - if ((p = malloc(size)) == NULL) { - DEBUG(0, ("smb_xmalloc() failed to allocate %lu bytes\n", (unsigned long)size)); - smb_panic("smb_xmalloc: malloc fail.\n"); + smb_panic("smb_xmalloc_array: called with zero size.\n"); + if (count >= MAX_ALLOC_SIZE/size) { + smb_panic("smb_xmalloc: alloc size too large.\n"); + } + if ((p = SMB_MALLOC(size*count)) == NULL) { + DEBUG(0, ("smb_xmalloc_array failed to allocate %lu * %lu bytes\n", + (unsigned long)size, (unsigned long)count)); + smb_panic("smb_xmalloc_array: malloc fail.\n"); } return p; } @@ -2134,7 +2222,7 @@ void *smb_xmemdup(const void *p, size_t size) { void *p2; - p2 = smb_xmalloc(size); + p2 = SMB_XMALLOC_ARRAY(unsigned char,size); memcpy(p2, p, size); return p2; } @@ -2145,7 +2233,15 @@ char *smb_xstrdup(const char *s) { +#if defined(PARANOID_MALLOC_CHECKER) +#ifdef strdup +#undef strdup +#endif +#endif char *s1 = strdup(s); +#if defined(PARANOID_MALLOC_CHECKER) +#define strdup(s) __ERROR_DONT_USE_STRDUP_DIRECTLY +#endif if (!s1) smb_panic("smb_xstrdup: malloc fail\n"); return s1; @@ -2157,7 +2254,15 @@ char *smb_xstrndup(const char *s, size_t n) { +#if defined(PARANOID_MALLOC_CHECKER) +#ifdef strndup +#undef strndup +#endif +#endif char *s1 = strndup(s, n); +#if defined(PARANOID_MALLOC_CHECKER) +#define strndup(s,n) __ERROR_DONT_USE_STRNDUP_DIRECTLY +#endif if (!s1) smb_panic("smb_xstrndup: malloc fail\n"); return s1; @@ -2189,7 +2294,7 @@ void *p2; if (size == 0) return NULL; - p2 = malloc(size); + p2 = SMB_MALLOC(size); if (!p2) return NULL; memcpy(p2, p, size); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/util_file.c samba-3.0.9/source/lib/util_file.c --- samba-3.0.9-orig/source/lib/util_file.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/util_file.c 2004-12-09 09:00:27.172622512 -0600 @@ -282,7 +282,7 @@ if (!s2) { maxlen = MIN(maxlen,8); - s = (char *)malloc(maxlen); + s = (char *)SMB_MALLOC(maxlen); } if (!s) { @@ -325,7 +325,7 @@ char *t; maxlen *= 2; - t = (char *)Realloc(s,maxlen); + t = (char *)SMB_REALLOC(s,maxlen); if (!t) { DEBUG(0,("fgets_slash: failed to expand buffer!\n")); SAFE_FREE(s); @@ -358,7 +358,7 @@ total = 0; while ((n = read(fd, buf, sizeof(buf))) > 0) { - tp = Realloc(p, total + n + 1); + tp = SMB_REALLOC(p, total + n + 1); if (!tp) { DEBUG(0,("file_pload: failed to expand buffer!\n")); close(fd); @@ -397,7 +397,7 @@ return NULL; } - p = (char *)malloc(sbuf.st_size+1); + p = (char *)SMB_MALLOC(sbuf.st_size+1); if (!p) { return NULL; } @@ -492,7 +492,7 @@ if (s[0] == '\n') i++; } - ret = (char **)malloc(sizeof(ret[0])*(i+2)); + ret = SMB_MALLOC_ARRAY(char *, i+2); if (!ret) { SAFE_FREE(p); return NULL; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/util_getent.c samba-3.0.9/source/lib/util_getent.c --- samba-3.0.9-orig/source/lib/util_getent.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/util_getent.c 2004-12-09 09:00:27.223609845 -0600 @@ -33,7 +33,7 @@ struct sys_grent *gent; struct group *grp; - gent = (struct sys_grent *) malloc(sizeof(struct sys_grent)); + gent = SMB_MALLOC_P(struct sys_grent); if (gent == NULL) { DEBUG (0, ("Out of memory in getgrent_list!\n")); return NULL; @@ -53,11 +53,11 @@ int i,num; if (grp->gr_name) { - if ((gent->gr_name = strdup(grp->gr_name)) == NULL) + if ((gent->gr_name = SMB_STRDUP(grp->gr_name)) == NULL) goto err; } if (grp->gr_passwd) { - if ((gent->gr_passwd = strdup(grp->gr_passwd)) == NULL) + if ((gent->gr_passwd = SMB_STRDUP(grp->gr_passwd)) == NULL) goto err; } gent->gr_gid = grp->gr_gid; @@ -67,20 +67,20 @@ ; /* alloc space for gr_mem string pointers */ - if ((gent->gr_mem = (char **) malloc((num+1) * sizeof(char *))) == NULL) + if ((gent->gr_mem = SMB_MALLOC_ARRAY(char *, num+1)) == NULL) goto err; memset(gent->gr_mem, '\0', (num+1) * sizeof(char *)); for (i=0; i < num; i++) { - if ((gent->gr_mem[i] = strdup(grp->gr_mem[i])) == NULL) + if ((gent->gr_mem[i] = SMB_STRDUP(grp->gr_mem[i])) == NULL) goto err; } gent->gr_mem[num] = NULL; grp = getgrent(); if (grp) { - gent->next = (struct sys_grent *) malloc(sizeof(struct sys_grent)); + gent->next = SMB_MALLOC_P(struct sys_grent); if (gent->next == NULL) goto err; gent = gent->next; @@ -134,7 +134,7 @@ struct sys_pwent *pent; struct passwd *pwd; - pent = (struct sys_pwent *) malloc(sizeof(struct sys_pwent)); + pent = SMB_MALLOC_P(struct sys_pwent); if (pent == NULL) { DEBUG (0, ("Out of memory in getpwent_list!\n")); return NULL; @@ -146,31 +146,31 @@ while (pwd != NULL) { memset(pent, '\0', sizeof(struct sys_pwent)); if (pwd->pw_name) { - if ((pent->pw_name = strdup(pwd->pw_name)) == NULL) + if ((pent->pw_name = SMB_STRDUP(pwd->pw_name)) == NULL) goto err; } if (pwd->pw_passwd) { - if ((pent->pw_passwd = strdup(pwd->pw_passwd)) == NULL) + if ((pent->pw_passwd = SMB_STRDUP(pwd->pw_passwd)) == NULL) goto err; } pent->pw_uid = pwd->pw_uid; pent->pw_gid = pwd->pw_gid; if (pwd->pw_gecos) { - if ((pent->pw_gecos = strdup(pwd->pw_gecos)) == NULL) + if ((pent->pw_gecos = SMB_STRDUP(pwd->pw_gecos)) == NULL) goto err; } if (pwd->pw_dir) { - if ((pent->pw_dir = strdup(pwd->pw_dir)) == NULL) + if ((pent->pw_dir = SMB_STRDUP(pwd->pw_dir)) == NULL) goto err; } if (pwd->pw_shell) { - if ((pent->pw_shell = strdup(pwd->pw_shell)) == NULL) + if ((pent->pw_shell = SMB_STRDUP(pwd->pw_shell)) == NULL) goto err; } pwd = getpwent(); if (pwd) { - pent->next = (struct sys_pwent *) malloc(sizeof(struct sys_pwent)); + pent->next = SMB_MALLOC_P(struct sys_pwent); if (pent->next == NULL) goto err; pent = pent->next; @@ -223,12 +223,12 @@ ; for (i = 0; i < num_users; i++) { - struct sys_userlist *entry = (struct sys_userlist *)malloc(sizeof(*entry)); + struct sys_userlist *entry = SMB_MALLOC_P(struct sys_userlist); if (entry == NULL) { free_userlist(list_head); return NULL; } - entry->unix_name = (char *)strdup(grp->gr_mem[i]); + entry->unix_name = (char *)SMB_STRDUP(grp->gr_mem[i]); if (entry->unix_name == NULL) { SAFE_FREE(entry); free_userlist(list_head); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/util_pw.c samba-3.0.9/source/lib/util_pw.c --- samba-3.0.9-orig/source/lib/util_pw.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/util_pw.c 2004-12-09 09:00:27.217611335 -0600 @@ -24,7 +24,7 @@ static struct passwd *alloc_copy_passwd(const struct passwd *from) { - struct passwd *ret = smb_xmalloc(sizeof(struct passwd)); + struct passwd *ret = SMB_XMALLOC_P(struct passwd); ZERO_STRUCTP(ret); ret->pw_name = smb_xstrdup(from->pw_name); ret->pw_passwd = smb_xstrdup(from->pw_passwd); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/util_sid.c samba-3.0.9/source/lib/util_sid.c --- samba-3.0.9-orig/source/lib/util_sid.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/lib/util_sid.c 2004-12-09 09:00:27.238606119 -0600 @@ -304,7 +304,7 @@ memset((char *)sidout, '\0', sizeof(DOM_SID)); - p = q = strdup(sidstr + 2); + p = q = SMB_STRDUP(sidstr + 2); if (p == NULL) { DEBUG(0, ("string_to_sid: out of memory!\n")); return False; @@ -621,7 +621,7 @@ { char *buf, *s; int len = sid_size(sid); - buf = malloc(len); + buf = SMB_MALLOC(len); if (!buf) return NULL; sid_linearize(buf, len, sid); @@ -641,7 +641,7 @@ if(!src) return NULL; - if((dst = talloc_zero(ctx, sizeof(DOM_SID))) != NULL) { + if((dst = TALLOC_ZERO_P(ctx, DOM_SID)) != NULL) { sid_copy( dst, src); } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/util_smbd.c samba-3.0.9/source/lib/util_smbd.c --- samba-3.0.9-orig/source/lib/util_smbd.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/util_smbd.c 2004-12-09 09:00:27.198616054 -0600 @@ -49,7 +49,7 @@ if (!pwd) return False; max_grp = groups_max(); - temp_groups = (gid_t *)malloc(sizeof(gid_t) * max_grp); + temp_groups = SMB_MALLOC_ARRAY(gid_t, max_grp); if (! temp_groups) { passwd_free(&pwd); return False; @@ -59,7 +59,7 @@ gid_t *groups_tmp; - groups_tmp = Realloc(temp_groups, sizeof(gid_t) * max_grp); + groups_tmp = SMB_REALLOC_ARRAY(temp_groups, gid_t, max_grp); if (!groups_tmp) { SAFE_FREE(temp_groups); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/util_str.c samba-3.0.9/source/lib/util_str.c --- samba-3.0.9-orig/source/lib/util_str.c 2004-11-15 21:03:18.000000000 -0600 +++ samba-3.0.9/source/lib/util_str.c 2004-12-09 09:00:27.193617296 -0600 @@ -134,7 +134,7 @@ *ctok=ictok; s=(char *)last_ptr; - if (!(ret=iret=malloc((ictok+1)*sizeof(char *)))) + if (!(ret=iret=SMB_MALLOC_ARRAY(char *,ictok+1))) return NULL; while(ictok--) { @@ -815,7 +815,7 @@ int i; char *hex_buffer; - *out_hex_buffer = smb_xmalloc((len*2)+1); + *out_hex_buffer = SMB_XMALLOC_ARRAY(char, (len*2)+1); hex_buffer = *out_hex_buffer; for (i = 0; i < len; i++) @@ -863,7 +863,7 @@ if (l == 0) { if (!null_string) { - if((null_string = (char *)malloc(1)) == NULL) { + if((null_string = (char *)SMB_MALLOC(1)) == NULL) { DEBUG(0,("string_init: malloc fail for null_string.\n")); return False; } @@ -871,7 +871,7 @@ } *dest = null_string; } else { - (*dest) = strdup(src); + (*dest) = SMB_STRDUP(src); if ((*dest) == NULL) { DEBUG(0,("Out of memory in string_init\n")); return False; @@ -990,7 +990,7 @@ s = string; - in = strdup(insert); + in = SMB_STRDUP(insert); if (!in) { DEBUG(0, ("realloc_string_sub: out of memory!\n")); return NULL; @@ -1019,7 +1019,7 @@ while ((p = strstr_m(s,pattern))) { if (ld > 0) { int offset = PTR_DIFF(s,string); - char *t = Realloc(string, ls + ld + 1); + char *t = SMB_REALLOC(string, ls + ld + 1); if (!t) { DEBUG(0, ("realloc_string_sub: out of memory!\n")); SAFE_FREE(in); @@ -1110,7 +1110,7 @@ } } - r = rp = (smb_ucs2_t *)malloc((lt + 1)*(sizeof(smb_ucs2_t))); + r = rp = SMB_MALLOC_ARRAY(smb_ucs2_t, lt + 1); if (!r) { DEBUG(0, ("all_string_sub_w: out of memory!\n")); return NULL; @@ -1478,7 +1478,7 @@ char *s; int i, j; const char *hex = "0123456789ABCDEF"; - s = malloc(len * 3 + 1); + s = SMB_MALLOC(len * 3 + 1); if (!s) return NULL; for (j=i=0;iuni_str_len+1)*4; if (!str->buffer) return NULL; - s = (char *)talloc(ctx, maxlen); /* convervative */ + s = (char *)TALLOC(ctx, maxlen); /* convervative */ if (!s) return NULL; pull_ucs2(NULL, s, str->buffer, maxlen, str->uni_str_len*2, STR_NOALIGN); @@ -586,7 +586,7 @@ smb_ucs2_t *dest; if (!len) len = strlen_w(src); - dest = (smb_ucs2_t *)malloc((len + 1) * sizeof(smb_ucs2_t)); + dest = SMB_MALLOC_ARRAY(smb_ucs2_t, len + 1); if (!dest) { DEBUG(0,("strdup_w: out of memory!\n")); return NULL; @@ -825,12 +825,12 @@ /* allocate UNISTR2 destination if not given */ if (!dst) { - dst = (UNISTR2*) talloc(ctx, sizeof(UNISTR2)); + dst = TALLOC_P(ctx, UNISTR2); if (!dst) return NULL; } if (!dst->buffer) { - dst->buffer = (uint16*) talloc(ctx, sizeof(uint16) * (len + 1)); + dst->buffer = TALLOC_ARRAY(ctx, uint16, len + 1); if (!dst->buffer) return NULL; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/wins_srv.c samba-3.0.9/source/lib/wins_srv.c --- samba-3.0.9-orig/source/lib/wins_srv.c 2004-11-15 21:03:19.000000000 -0600 +++ samba-3.0.9/source/lib/wins_srv.c 2004-12-09 09:00:27.209613322 -0600 @@ -72,8 +72,8 @@ { char *keystr = NULL, *wins_ip_addr = NULL, *src_ip_addr = NULL; - wins_ip_addr = strdup(inet_ntoa(wins_ip)); - src_ip_addr = strdup(inet_ntoa(src_ip)); + wins_ip_addr = SMB_STRDUP(inet_ntoa(wins_ip)); + src_ip_addr = SMB_STRDUP(inet_ntoa(src_ip)); if ( !wins_ip_addr || !src_ip_addr ) { DEBUG(0,("wins_srv_keystr: malloc error\n")); @@ -212,9 +212,9 @@ if (lp_wins_support()) { /* give the caller something to chew on. This makes the rest of the logic simpler (ie. less special cases) */ - ret = (char **)malloc(sizeof(char *)*2); + ret = SMB_MALLOC_ARRAY(char *, 2); if (!ret) return NULL; - ret[0] = strdup("*"); + ret[0] = SMB_STRDUP("*"); ret[1] = NULL; return ret; } @@ -242,8 +242,8 @@ } /* add it to the list */ - ret = (char **)Realloc(ret, (count+2) * sizeof(char *)); - ret[count] = strdup(t_ip.tag); + ret = SMB_REALLOC_ARRAY(ret, char *, count+2); + ret[count] = SMB_STRDUP(t_ip.tag); if (!ret[count]) break; count++; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/xfile.c samba-3.0.9/source/lib/xfile.c --- samba-3.0.9-orig/source/lib/xfile.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/lib/xfile.c 2004-12-09 09:00:27.236606616 -0600 @@ -80,7 +80,7 @@ { if (f->buf) return 1; if (f->bufsize == 0) return 0; - f->buf = malloc(f->bufsize); + f->buf = SMB_MALLOC(f->bufsize); if (!f->buf) return 0; f->next = f->buf; return 1; @@ -95,7 +95,7 @@ { XFILE *ret; - ret = (XFILE *)malloc(sizeof(XFILE)); + ret = SMB_MALLOC_P(XFILE); if (!ret) return NULL; memset(ret, 0, sizeof(XFILE)); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libads/ads_struct.c samba-3.0.9/source/libads/ads_struct.c --- samba-3.0.9-orig/source/libads/ads_struct.c 2004-11-15 21:03:32.000000000 -0600 +++ samba-3.0.9/source/libads/ads_struct.c 2004-12-09 09:00:27.526534585 -0600 @@ -31,7 +31,7 @@ char *ret; int len; - r = strdup(realm); + r = SMB_STRDUP(realm); if (!r || !*r) return r; @@ -42,7 +42,7 @@ len = (numbits+1)*(strlen(field)+1) + strlen(r) + 1; - ret = malloc(len); + ret = SMB_MALLOC(len); if (!ret) return NULL; @@ -87,12 +87,12 @@ { ADS_STRUCT *ads; - ads = (ADS_STRUCT *)smb_xmalloc(sizeof(*ads)); + ads = SMB_XMALLOC_P(ADS_STRUCT); ZERO_STRUCTP(ads); - ads->server.realm = realm? strdup(realm) : NULL; - ads->server.workgroup = workgroup ? strdup(workgroup) : NULL; - ads->server.ldap_server = ldap_server? strdup(ldap_server) : NULL; + ads->server.realm = realm? SMB_STRDUP(realm) : NULL; + ads->server.workgroup = workgroup ? SMB_STRDUP(workgroup) : NULL; + ads->server.ldap_server = ldap_server? SMB_STRDUP(ldap_server) : NULL; /* we need to know if this is a foreign realm */ if (realm && *realm && !strequal(lp_realm(), realm)) { diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libads/authdata.c samba-3.0.9/source/libads/authdata.c --- samba-3.0.9-orig/source/libads/authdata.c 2004-11-15 21:03:32.000000000 -0600 +++ samba-3.0.9/source/libads/authdata.c 2004-12-09 09:00:27.536532101 -0600 @@ -59,7 +59,7 @@ return False; if (UNMARSHALLING(ps) && type_10->len) { - type_10->username = (uint16 *) prs_alloc_mem(ps, type_10->len); + type_10->username = PRS_ALLOC_MEM(ps, uint16, type_10->len); if (!type_10->username) { DEBUG(3, ("No memory available\n")); return False; @@ -85,8 +85,7 @@ depth++; if (UNMARSHALLING(ps)) { - sid_and_attr->sid = - (DOM_SID2 * ) prs_alloc_mem(ps, sizeof(DOM_SID2)); + sid_and_attr->sid = PRS_ALLOC_MEM(ps, DOM_SID2, 1); if (!sid_and_attr->sid) { DEBUG(3, ("No memory available\n")); return False; @@ -135,8 +134,7 @@ return False; if (UNMARSHALLING(ps)) { - array->krb_sid_and_attrs = (KRB_SID_AND_ATTRS *) - prs_alloc_mem(ps, sizeof(KRB_SID_AND_ATTRS) * num); + array->krb_sid_and_attrs = PRS_ALLOC_MEM(ps, KRB_SID_AND_ATTRS, num); if (!array->krb_sid_and_attrs) { DEBUG(3, ("No memory available\n")); return False; @@ -199,8 +197,7 @@ return False; if (UNMARSHALLING(ps)) { - array->group_membership = (GROUP_MEMBERSHIP *) - prs_alloc_mem(ps, sizeof(GROUP_MEMBERSHIP) * num); + array->group_membership = PRS_ALLOC_MEM(ps, GROUP_MEMBERSHIP, num); if (!array->group_membership) { DEBUG(3, ("No memory available\n")); return False; @@ -423,7 +420,7 @@ if (!prs_uint32("type", ps, depth, &data->type)) return False; if (UNMARSHALLING(ps)) { - data->signature = (unsigned char *)prs_alloc_mem(ps, siglen); + data->signature = PRS_ALLOC_MEM(ps, unsigned char, siglen); if (!data->signature) { DEBUG(3, ("No memory available\n")); return False; @@ -454,8 +451,7 @@ } if (UNMARSHALLING(ps) && hdr->size > 0) { - hdr->ctr = (PAC_INFO_CTR *) - prs_alloc_mem(ps, sizeof(PAC_INFO_CTR)); + hdr->ctr = PRS_ALLOC_MEM(ps, PAC_INFO_CTR, 1); if (!hdr->ctr) { DEBUG(3, ("No memory available\n")); return False; @@ -466,8 +462,7 @@ case PAC_TYPE_LOGON_INFO: DEBUG(5, ("PAC_TYPE_LOGON_INFO\n")); if (UNMARSHALLING(ps)) - hdr->ctr->pac.logon_info = (PAC_LOGON_INFO *) - prs_alloc_mem(ps, sizeof(PAC_LOGON_INFO)); + hdr->ctr->pac.logon_info = PRS_ALLOC_MEM(ps, PAC_LOGON_INFO, 1); if (!hdr->ctr->pac.logon_info) { DEBUG(3, ("No memory available\n")); return False; @@ -480,8 +475,7 @@ case PAC_TYPE_SERVER_CHECKSUM: DEBUG(5, ("PAC_TYPE_SERVER_CHECKSUM\n")); if (UNMARSHALLING(ps)) - hdr->ctr->pac.srv_cksum = (PAC_SIGNATURE_DATA *) - prs_alloc_mem(ps, sizeof(PAC_SIGNATURE_DATA)); + hdr->ctr->pac.srv_cksum = PRS_ALLOC_MEM(ps, PAC_SIGNATURE_DATA, 1); if (!hdr->ctr->pac.srv_cksum) { DEBUG(3, ("No memory available\n")); return False; @@ -494,8 +488,7 @@ case PAC_TYPE_PRIVSVR_CHECKSUM: DEBUG(5, ("PAC_TYPE_PRIVSVR_CHECKSUM\n")); if (UNMARSHALLING(ps)) - hdr->ctr->pac.privsrv_cksum = (PAC_SIGNATURE_DATA *) - prs_alloc_mem(ps, sizeof(PAC_SIGNATURE_DATA)); + hdr->ctr->pac.privsrv_cksum = PRS_ALLOC_MEM(ps, PAC_SIGNATURE_DATA, 1); if (!hdr->ctr->pac.privsrv_cksum) { DEBUG(3, ("No memory available\n")); return False; @@ -509,8 +502,7 @@ case PAC_TYPE_UNKNOWN_10: DEBUG(5, ("PAC_TYPE_UNKNOWN_10\n")); if (UNMARSHALLING(ps)) - hdr->ctr->pac.type_10 = (UNKNOWN_TYPE_10 *) - prs_alloc_mem(ps, sizeof(UNKNOWN_TYPE_10)); + hdr->ctr->pac.type_10 = PRS_ALLOC_MEM(ps, UNKNOWN_TYPE_10, 1); if (!hdr->ctr->pac.type_10) { DEBUG(3, ("No memory available\n")); return False; @@ -571,9 +563,7 @@ return False; if (UNMARSHALLING(ps) && data->num_buffers > 0) { - if ((data->pac_info_hdr_ptr = (PAC_INFO_HDR *) - prs_alloc_mem(ps, sizeof(PAC_INFO_HDR) * - data->num_buffers)) == NULL) { + if ((data->pac_info_hdr_ptr = PRS_ALLOC_MEM(ps, PAC_INFO_HDR, data->num_buffers)) == NULL) { return False; } } @@ -606,7 +596,7 @@ data_blob_free(&pac_data_blob); - pac_data = (PAC_DATA *) talloc_zero(ctx, sizeof(PAC_DATA)); + pac_data = TALLOC_ZERO_P(ctx, PAC_DATA); pac_io_pac_data("pac data", pac_data, &ps, 0); prs_mem_free(&ps); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libads/kerberos_keytab.c samba-3.0.9/source/libads/kerberos_keytab.c --- samba-3.0.9-orig/source/libads/kerberos_keytab.c 2004-11-15 21:03:32.000000000 -0600 +++ samba-3.0.9/source/libads/kerberos_keytab.c 2004-12-09 09:00:27.524535082 -0600 @@ -546,7 +546,7 @@ if (!found) { goto done; } - oldEntries = (char **) malloc(found * sizeof(char *)); + oldEntries = SMB_MALLOC_ARRAY(char *, found ); if (!oldEntries) { DEBUG(1,("ads_keytab_create_default: Failed to allocate space to store the old keytab entries (malloc failed?).\n")); ret = -1; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libads/kerberos_verify.c samba-3.0.9/source/libads/kerberos_verify.c --- samba-3.0.9-orig/source/libads/kerberos_verify.c 2004-11-15 21:03:32.000000000 -0600 +++ samba-3.0.9/source/libads/kerberos_verify.c 2004-12-09 09:00:27.521535827 -0600 @@ -174,7 +174,7 @@ for (i=0;enctypes[i];i++) { krb5_keyblock *key = NULL; - if (!(key = (krb5_keyblock *)malloc(sizeof(*key)))) { + if (!(key = SMB_MALLOC_P(krb5_keyblock))) { goto out; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libads/krb5_setpw.c samba-3.0.9/source/libads/krb5_setpw.c --- samba-3.0.9-orig/source/libads/krb5_setpw.c 2004-11-15 21:03:32.000000000 -0600 +++ samba-3.0.9/source/libads/krb5_setpw.c 2004-12-09 09:00:27.534532598 -0600 @@ -54,7 +54,7 @@ DATA_BLOB ret; - princ = strdup(principal); + princ = SMB_STRDUP(principal); if ((c = strchr_m(princ, '/')) == NULL) { c = princ; @@ -156,7 +156,7 @@ return ret; } - packet->data = (char *)malloc(ap_req->length + cipherpw.length + 6); + packet->data = (char *)SMB_MALLOC(ap_req->length + cipherpw.length + 6); if (!packet->data) return -1; @@ -407,7 +407,7 @@ free(chpw_req.data); chpw_rep.length = 1500; - chpw_rep.data = (char *) malloc(chpw_rep.length); + chpw_rep.data = (char *) SMB_MALLOC(chpw_rep.length); if (!chpw_rep.data) { close(sock); free(ap_req.data); @@ -631,7 +631,7 @@ /* We have to obtain an INITIAL changepw ticket for changing password */ asprintf(&chpw_princ, "kadmin/changepw@%s", (char *) krb5_princ_realm(context, princ)); - password = strdup(oldpw); + password = SMB_STRDUP(oldpw); ret = krb5_get_init_creds_password(context, &creds, princ, password, kerb_prompter, NULL, 0, chpw_princ, &opts); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libads/ldap.c samba-3.0.9/source/libads/ldap.c --- samba-3.0.9-orig/source/libads/ldap.c 2004-11-15 21:03:32.000000000 -0600 +++ samba-3.0.9/source/libads/ldap.c 2004-12-09 09:00:27.530533592 -0600 @@ -85,7 +85,7 @@ DEBUG(5,("ads_try_connect: trying ldap server '%s' port %u\n", server, port)); /* this copes with inet_ntoa brokenness */ - srv = strdup(server); + srv = SMB_STRDUP(server); ads->ld = ldap_open_with_timeout(srv, port, lp_ldap_timeout()); if (!ads->ld) { @@ -262,11 +262,11 @@ } if (!ads->auth.realm) { - ads->auth.realm = strdup(ads->config.realm); + ads->auth.realm = SMB_STRDUP(ads->config.realm); } if (!ads->auth.kdc_server) { - ads->auth.kdc_server = strdup(inet_ntoa(ads->ldap_ip)); + ads->auth.kdc_server = SMB_STRDUP(inet_ntoa(ads->ldap_ip)); } #if KRB5_DNS_HACK @@ -304,13 +304,13 @@ if (!in_val) return NULL; - value = talloc_zero(ctx, sizeof(struct berval)); + value = TALLOC_ZERO_P(ctx, struct berval); if (value == NULL) return NULL; if (in_val->bv_len == 0) return value; value->bv_len = in_val->bv_len; - value->bv_val = talloc_memdup(ctx, in_val->bv_val, in_val->bv_len); + value->bv_val = TALLOC_MEMDUP(ctx, in_val->bv_val, in_val->bv_len); return value; } @@ -324,9 +324,9 @@ int i; if (!in_vals) return NULL; - for (i=0; in_vals[i]; i++); /* count values */ - values = (struct berval **) talloc_zero(ctx, - (i+1)*sizeof(struct berval *)); + for (i=0; in_vals[i]; i++) + ; /* count values */ + values = TALLOC_ZERO_ARRAY(ctx, struct berval *, i+1); if (!values) return NULL; for (i=0; in_vals[i]; i++) { @@ -344,8 +344,9 @@ int i; if (!in_vals) return NULL; - for (i=0; in_vals[i]; i++); /* count values */ - values = (char ** ) talloc_zero(ctx, (i+1)*sizeof(char *)); + for (i=0; in_vals[i]; i++) + ; /* count values */ + values = TALLOC_ZERO_ARRAY(ctx, char *, i+1); if (!values) return NULL; for (i=0; in_vals[i]; i++) { @@ -363,8 +364,9 @@ int i; if (!in_vals) return NULL; - for (i=0; in_vals[i]; i++); /* count values */ - values = (char **) talloc_zero(ctx, (i+1)*sizeof(char *)); + for (i=0; in_vals[i]; i++) + ; /* count values */ + values = TALLOC_ZERO_ARRAY(ctx, char *, i+1); if (!values) return NULL; for (i=0; in_vals[i]; i++) { @@ -787,8 +789,7 @@ #define ADS_MODLIST_ALLOC_SIZE 10 LDAPMod **mods; - if ((mods = (LDAPMod **) talloc_zero(ctx, sizeof(LDAPMod *) * - (ADS_MODLIST_ALLOC_SIZE + 1)))) + if ((mods = TALLOC_ZERO_ARRAY(ctx, LDAPMod *, ADS_MODLIST_ALLOC_SIZE + 1))) /* -1 is safety to make sure we don't go over the end. need to reset it to NULL before doing ldap modify */ mods[ADS_MODLIST_ALLOC_SIZE] = (LDAPMod *) -1; @@ -824,8 +825,8 @@ for (curmod=0; modlist[curmod] && modlist[curmod] != (LDAPMod *) -1; curmod++); if (modlist[curmod] == (LDAPMod *) -1) { - if (!(modlist = talloc_realloc(ctx, modlist, - (curmod+ADS_MODLIST_ALLOC_SIZE+1)*sizeof(LDAPMod *)))) + if (!(modlist = TALLOC_REALLOC_ARRAY(ctx, modlist, LDAPMod *, + curmod+ADS_MODLIST_ALLOC_SIZE+1))) return ADS_ERROR(LDAP_NO_MEMORY); memset(&modlist[curmod], 0, ADS_MODLIST_ALLOC_SIZE*sizeof(LDAPMod *)); @@ -833,7 +834,7 @@ *mods = modlist; } - if (!(modlist[curmod] = talloc_zero(ctx, sizeof(LDAPMod)))) + if (!(modlist[curmod] = TALLOC_ZERO_P(ctx, LDAPMod))) return ADS_ERROR(LDAP_NO_MEMORY); modlist[curmod]->mod_type = talloc_strdup(ctx, name); if (mod_op & LDAP_MOD_BVALUES) { @@ -1009,11 +1010,11 @@ ret = ads_default_ou_string(ads, WELL_KNOWN_GUID_COMPUTERS); /* samba4 might not yet respond to a wellknownobject-query */ - return ret ? ret : strdup("cn=Computers"); + return ret ? ret : SMB_STRDUP("cn=Computers"); } if (strequal(org_unit, "Computers")) { - return strdup("cn=Computers"); + return SMB_STRDUP("cn=Computers"); } return ads_build_path(org_unit, "\\/", "ou=", 1); @@ -1070,7 +1071,7 @@ for (i=1; i < new_ln; i++) { char *s; asprintf(&s, "%s,%s", ret, wkn_dn_exp[i]); - ret = strdup(s); + ret = SMB_STRDUP(s); free(s); } @@ -1704,7 +1705,7 @@ char *machine; /* machine name must be lowercase */ - machine = strdup(machine_name); + machine = SMB_STRDUP(machine_name); strlower_m(machine); /* @@ -1754,7 +1755,7 @@ int rc; /* hostname must be lowercase */ - host = strdup(hostname); + host = SMB_STRDUP(hostname); strlower_m(host); status = ads_find_machine_acct(ads, &res, host); @@ -1878,7 +1879,7 @@ if (!(mods = ads_init_mods(ctx))) return ADS_ERROR(LDAP_NO_MEMORY); bval.bv_len = prs_offset(&ps_wire); - bval.bv_val = talloc(ctx, bval.bv_len); + bval.bv_val = TALLOC(ctx, bval.bv_len); if (!bval.bv_val) { ret = ADS_ERROR(LDAP_NO_MEMORY); goto ads_set_sd_error; @@ -1978,7 +1979,7 @@ *num_values = ldap_count_values(values); - ret = talloc(mem_ctx, sizeof(char *) * (*num_values+1)); + ret = TALLOC_ARRAY(mem_ctx, char *, *num_values + 1); if (!ret) { ldap_value_free(values); return NULL; @@ -2089,9 +2090,8 @@ return NULL; } - strings = talloc_realloc(mem_ctx, current_strings, - sizeof(*current_strings) * - (*num_strings + num_new_strings)); + strings = TALLOC_REALLOC_ARRAY(mem_ctx, current_strings, char *, + *num_strings + num_new_strings); if (strings == NULL) { ldap_memfree(range_attr); @@ -2228,7 +2228,7 @@ for (i=0; values[i]; i++) /* nop */ ; - (*sids) = talloc(mem_ctx, sizeof(DOM_SID) * i); + (*sids) = TALLOC_ARRAY(mem_ctx, DOM_SID, i); if (!(*sids)) { ldap_value_free_len(values); return 0; @@ -2409,7 +2409,7 @@ SAFE_FREE(ads->config.ldap_server_name); - ads->config.ldap_server_name = strdup(p+1); + ads->config.ldap_server_name = SMB_STRDUP(p+1); p = strchr(ads->config.ldap_server_name, '$'); if (!p || p[1] != '@') { talloc_destroy(ctx); @@ -2424,7 +2424,7 @@ SAFE_FREE(ads->config.realm); SAFE_FREE(ads->config.bind_path); - ads->config.realm = strdup(p+2); + ads->config.realm = SMB_STRDUP(p+2); ads->config.bind_path = ads_build_dn(ads->config.realm); DEBUG(3,("got ldap server name %s@%s, using bind path: %s\n", diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libads/ldap_printer.c samba-3.0.9/source/libads/ldap_printer.c --- samba-3.0.9-orig/source/libads/ldap_printer.c 2004-11-15 21:03:32.000000000 -0600 +++ samba-3.0.9/source/libads/ldap_printer.c 2004-12-09 09:00:27.532533095 -0600 @@ -161,10 +161,9 @@ }; if (num_vals) { - str_values = talloc(ctx, - (num_vals + 1) * sizeof(smb_ucs2_t *)); + str_values = TALLOC_ARRAY(ctx, char *, num_vals + 1); memset(str_values, '\0', - (num_vals + 1) * sizeof(smb_ucs2_t *)); + (num_vals + 1) * sizeof(char *)); cur_str = (smb_ucs2_t *) value->data_p; for (i=0; i < num_vals; i++) diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libads/ldap_utils.c samba-3.0.9/source/libads/ldap_utils.c --- samba-3.0.9-orig/source/libads/ldap_utils.c 2004-11-15 21:03:32.000000000 -0600 +++ samba-3.0.9/source/libads/ldap_utils.c 2004-12-09 09:00:27.519536324 -0600 @@ -42,7 +42,7 @@ return ADS_ERROR(LDAP_SERVER_DOWN); } - bp = strdup(bind_path); + bp = SMB_STRDUP(bind_path); if (!bp) { return ADS_ERROR_NT(NT_STATUS_NO_MEMORY); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libads/sasl.c samba-3.0.9/source/libads/sasl.c --- samba-3.0.9-orig/source/libads/sasl.c 2004-11-15 21:03:32.000000000 -0600 +++ samba-3.0.9/source/libads/sasl.c 2004-12-09 09:00:27.523535330 -0600 @@ -374,7 +374,7 @@ gss_release_buffer(&minor_status, &output_token); - output_token.value = malloc(strlen(ads->config.bind_path) + 8); + output_token.value = SMB_MALLOC(strlen(ads->config.bind_path) + 8); p = output_token.value; *p++ = 1; /* no sign & seal selection */ diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/asn1.c samba-3.0.9/source/libsmb/asn1.c --- samba-3.0.9-orig/source/libsmb/asn1.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/libsmb/asn1.c 2004-12-09 09:00:27.272597674 -0600 @@ -32,7 +32,7 @@ if (data->has_error) return False; if (data->length < data->ofs+len) { uint8 *newp; - newp = Realloc(data->data, data->ofs+len); + newp = SMB_REALLOC(data->data, data->ofs+len); if (!newp) { SAFE_FREE(data->data); data->has_error = True; @@ -58,7 +58,7 @@ struct nesting *nesting; asn1_write_uint8(data, tag); - nesting = (struct nesting *)malloc(sizeof(struct nesting)); + nesting = SMB_MALLOC_P(struct nesting); if (!nesting) { data->has_error = True; return False; @@ -255,7 +255,7 @@ data->has_error = True; return False; } - nesting = (struct nesting *)malloc(sizeof(struct nesting)); + nesting = SMB_MALLOC_P(struct nesting); if (!nesting) { data->has_error = True; return False; @@ -350,7 +350,7 @@ asn1_end_tag(data); - *OID = strdup(oid_str); + *OID = SMB_STRDUP(oid_str); return !data->has_error; } @@ -380,7 +380,7 @@ data->has_error = True; return False; } - *s = malloc(len+1); + *s = SMB_MALLOC(len+1); if (! *s) { data->has_error = True; return False; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/clientgen.c samba-3.0.9/source/libsmb/clientgen.c --- samba-3.0.9-orig/source/libsmb/clientgen.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/libsmb/clientgen.c 2004-12-09 09:00:27.263599910 -0600 @@ -253,7 +253,7 @@ } if (!cli) { - cli = (struct cli_state *)malloc(sizeof(*cli)); + cli = SMB_MALLOC_P(struct cli_state); if (!cli) return NULL; ZERO_STRUCTP(cli); @@ -275,8 +275,8 @@ cli->timeout = 20000; /* Timeout is in milliseconds. */ cli->bufsize = CLI_BUFFER_SIZE+4; cli->max_xmit = cli->bufsize; - cli->outbuf = (char *)malloc(cli->bufsize+SAFETY_MARGIN); - cli->inbuf = (char *)malloc(cli->bufsize+SAFETY_MARGIN); + cli->outbuf = (char *)SMB_MALLOC(cli->bufsize+SAFETY_MARGIN); + cli->inbuf = (char *)SMB_MALLOC(cli->bufsize+SAFETY_MARGIN); cli->oplock_handler = cli_oplock_ack; cli->case_sensitive = False; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/clifile.c samba-3.0.9/source/libsmb/clifile.c --- samba-3.0.9-orig/source/libsmb/clifile.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/libsmb/clifile.c 2004-12-09 09:00:27.286594197 -0600 @@ -1302,7 +1302,7 @@ pstring path2; clistr_pull(cli, path2, p, sizeof(path2), len, STR_ASCII); - *tmp_path = strdup(path2); + *tmp_path = SMB_STRDUP(path2); } return SVAL(cli->inbuf,smb_vwv0); @@ -1353,7 +1353,7 @@ size_t ea_namelen = strlen(ea_name); data_len = 4 + 4 + ea_namelen + 1 + ea_len; - data = malloc(data_len); + data = SMB_MALLOC(data_len); if (!data) { return False; } @@ -1509,7 +1509,7 @@ goto out; } - ea_list = (struct ea_struct *)talloc(ctx, num_eas*sizeof(struct ea_struct)); + ea_list = TALLOC_ARRAY(ctx, struct ea_struct, num_eas); if (!ea_list) { goto out; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/clilist.c samba-3.0.9/source/libsmb/clilist.c --- samba-3.0.9-orig/source/libsmb/clilist.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/libsmb/clilist.c 2004-12-09 09:00:27.277596432 -0600 @@ -282,7 +282,7 @@ } /* and add them to the dirlist pool */ - tdl = Realloc(dirlist,dirlist_len + data_len); + tdl = SMB_REALLOC(dirlist,dirlist_len + data_len); if (!tdl) { DEBUG(0,("cli_list_new: Failed to expand dirlist\n")); @@ -413,7 +413,7 @@ first = False; - tdl = Realloc(dirlist,(num_received + received)*DIR_STRUCT_SIZE); + tdl = SMB_REALLOC(dirlist,(num_received + received)*DIR_STRUCT_SIZE); if (!tdl) { DEBUG(0,("cli_list_old: failed to expand dirlist")); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/cliquota.c samba-3.0.9/source/libsmb/cliquota.c --- samba-3.0.9-orig/source/libsmb/cliquota.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/libsmb/cliquota.c 2004-12-09 09:00:27.266599164 -0600 @@ -321,12 +321,12 @@ goto cleanup; } - if ((tmp_list_ent=(SMB_NTQUOTA_LIST *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_LIST)))==NULL) { + if ((tmp_list_ent=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_LIST))==NULL) { DEBUG(0,("talloc_zero() failed\n")); return (-1); } - if ((tmp_list_ent->quotas=(SMB_NTQUOTA_STRUCT *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_STRUCT)))==NULL) { + if ((tmp_list_ent->quotas=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_STRUCT))==NULL) { DEBUG(0,("talloc_zero() failed\n")); return (-1); } @@ -379,13 +379,13 @@ goto cleanup; } - if ((tmp_list_ent=(SMB_NTQUOTA_LIST *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_LIST)))==NULL) { + if ((tmp_list_ent=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_LIST))==NULL) { DEBUG(0,("talloc_zero() failed\n")); talloc_destroy(mem_ctx); goto cleanup; } - if ((tmp_list_ent->quotas=(SMB_NTQUOTA_STRUCT *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_STRUCT)))==NULL) { + if ((tmp_list_ent->quotas=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_STRUCT))==NULL) { DEBUG(0,("talloc_zero() failed\n")); talloc_destroy(mem_ctx); goto cleanup; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/clireadwrite.c samba-3.0.9/source/libsmb/clireadwrite.c --- samba-3.0.9-orig/source/libsmb/clireadwrite.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/libsmb/clireadwrite.c 2004-12-09 09:00:27.290593203 -0600 @@ -256,8 +256,8 @@ BOOL bigoffset = False; if (size > cli->bufsize) { - cli->outbuf = realloc(cli->outbuf, size + 1024); - cli->inbuf = realloc(cli->inbuf, size + 1024); + cli->outbuf = SMB_REALLOC(cli->outbuf, size + 1024); + cli->inbuf = SMB_REALLOC(cli->inbuf, size + 1024); if (cli->outbuf == NULL || cli->inbuf == NULL) return False; cli->bufsize = size + 1024; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/clitrans.c samba-3.0.9/source/libsmb/clitrans.c --- samba-3.0.9-orig/source/libsmb/clitrans.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/libsmb/clitrans.c 2004-12-09 09:00:27.292592706 -0600 @@ -210,7 +210,7 @@ /* allocate it */ if (total_data!=0) { - tdata = Realloc(*data,total_data); + tdata = SMB_REALLOC(*data,total_data); if (!tdata) { DEBUG(0,("cli_receive_trans: failed to enlarge data buffer\n")); cli_signing_trans_stop(cli); @@ -221,7 +221,7 @@ } if (total_param!=0) { - tparam = Realloc(*param,total_param); + tparam = SMB_REALLOC(*param,total_param); if (!tparam) { DEBUG(0,("cli_receive_trans: failed to enlarge param buffer\n")); cli_signing_trans_stop(cli); @@ -527,7 +527,7 @@ /* allocate it */ if (total_data) { - tdata = Realloc(*data,total_data); + tdata = SMB_REALLOC(*data,total_data); if (!tdata) { DEBUG(0,("cli_receive_nt_trans: failed to enlarge data buffer to %d\n",total_data)); cli_signing_trans_stop(cli); @@ -538,7 +538,7 @@ } if (total_param) { - tparam = Realloc(*param,total_param); + tparam = SMB_REALLOC(*param,total_param); if (!tparam) { DEBUG(0,("cli_receive_nt_trans: failed to enlarge param buffer to %d\n", total_param)); cli_signing_trans_stop(cli); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/conncache.c samba-3.0.9/source/libsmb/conncache.c --- samba-3.0.9-orig/source/libsmb/conncache.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/libsmb/conncache.c 2004-12-09 09:00:27.293592458 -0600 @@ -115,8 +115,7 @@ /* Create negative lookup cache entry for this domain and controller */ - if ( !(fcc = (struct failed_connection_cache *)malloc(sizeof(struct failed_connection_cache))) ) - { + if ( !(fcc = SMB_MALLOC_P(struct failed_connection_cache)) ) { DEBUG(0, ("malloc failed in add_failed_connection_entry!\n")); return; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/libsmb_cache.c samba-3.0.9/source/libsmb/libsmb_cache.c --- samba-3.0.9-orig/source/libsmb/libsmb_cache.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/libsmb/libsmb_cache.c 2004-12-09 09:00:27.295591961 -0600 @@ -55,7 +55,7 @@ { struct smbc_server_cache * srvcache = NULL; - if (!(srvcache = malloc(sizeof(*srvcache)))) { + if (!(srvcache = SMB_MALLOC_P(struct smbc_server_cache))) { errno = ENOMEM; DEBUG(3, ("Not enough space for server cache allocation\n")); return 1; @@ -65,25 +65,25 @@ srvcache->server = new; - srvcache->server_name = strdup(server); + srvcache->server_name = SMB_STRDUP(server); if (!srvcache->server_name) { errno = ENOMEM; goto failed; } - srvcache->share_name = strdup(share); + srvcache->share_name = SMB_STRDUP(share); if (!srvcache->share_name) { errno = ENOMEM; goto failed; } - srvcache->workgroup = strdup(workgroup); + srvcache->workgroup = SMB_STRDUP(workgroup); if (!srvcache->workgroup) { errno = ENOMEM; goto failed; } - srvcache->username = strdup(username); + srvcache->username = SMB_STRDUP(username); if (!srvcache->username) { errno = ENOMEM; goto failed; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/libsmbclient.c samba-3.0.9/source/libsmb/libsmbclient.c --- samba-3.0.9-orig/source/libsmb/libsmbclient.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/libsmb/libsmbclient.c 2004-12-09 09:00:27.282595190 -0600 @@ -99,7 +99,7 @@ } /* make a copy of the old one */ - new_usegment = (char*)malloc( old_length * 3 + 1 ); + new_usegment = (char*)SMB_MALLOC( old_length * 3 + 1 ); while( i < old_length ) { int bReencode = False; @@ -671,7 +671,7 @@ * Let's find a free server_fd */ - srv = (SMBCSRV *)malloc(sizeof(*srv)); + srv = SMB_MALLOC_P(SMBCSRV); if (!srv) { errno = ENOMEM; goto failed; @@ -776,7 +776,7 @@ return NULL; } - ipc_srv = (SMBCSRV *)malloc(sizeof(*ipc_srv)); + ipc_srv = SMB_MALLOC_P(SMBCSRV); if (!ipc_srv) { errno = ENOMEM; cli_shutdown(ipc_cli); @@ -871,7 +871,7 @@ } else { - file = malloc(sizeof(SMBCFILE)); + file = SMB_MALLOC_P(SMBCFILE); if (!file) { @@ -895,7 +895,7 @@ /* Fill in file struct */ file->cli_fd = fd; - file->fname = strdup(fname); + file->fname = SMB_STRDUP(fname); file->srv = srv; file->offset = 0; file->file = True; @@ -1629,7 +1629,7 @@ size = sizeof(struct smbc_dirent) + u_name_len + u_comment_len + 1; - dirent = malloc(size); + dirent = SMB_MALLOC(size); if (!dirent) { @@ -1642,7 +1642,7 @@ if (dir->dir_list == NULL) { - dir->dir_list = malloc(sizeof(struct smbc_dir_list)); + dir->dir_list = SMB_MALLOC_P(struct smbc_dir_list); if (!dir->dir_list) { SAFE_FREE(dirent); @@ -1656,7 +1656,7 @@ } else { - dir->dir_end->next = malloc(sizeof(struct smbc_dir_list)); + dir->dir_end->next = SMB_MALLOC_P(struct smbc_dir_list); if (!dir->dir_end->next) { @@ -1835,7 +1835,7 @@ pstrcpy(workgroup, context->workgroup); - dir = malloc(sizeof(*dir)); + dir = SMB_MALLOC_P(SMBCFILE); if (!dir) { @@ -1847,7 +1847,7 @@ ZERO_STRUCTP(dir); dir->cli_fd = 0; - dir->fname = strdup(fname); + dir->fname = SMB_STRDUP(fname); dir->srv = NULL; dir->offset = 0; dir->file = False; @@ -3110,7 +3110,7 @@ return True; } - aces = calloc(1+(*the_acl)->num_aces,sizeof(SEC_ACE)); + aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces); memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE)); memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE)); new = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces); @@ -3143,7 +3143,7 @@ } if (StrnCaseCmp(tok,"OWNER:", 6) == 0) { - owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); + owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1); if (!owner_sid || !convert_string_to_sid(ipc_cli, pol, numeric, @@ -3155,7 +3155,7 @@ } if (StrnCaseCmp(tok,"OWNER+:", 7) == 0) { - owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); + owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1); if (!owner_sid || !convert_string_to_sid(ipc_cli, pol, False, @@ -3167,7 +3167,7 @@ } if (StrnCaseCmp(tok,"GROUP:", 6) == 0) { - grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); + grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1); if (!grp_sid || !convert_string_to_sid(ipc_cli, pol, numeric, @@ -3179,7 +3179,7 @@ } if (StrnCaseCmp(tok,"GROUP+:", 7) == 0) { - grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID)); + grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1); if (!grp_sid || !convert_string_to_sid(ipc_cli, pol, False, @@ -4273,7 +4273,7 @@ { SMBCCTX * context; - context = malloc(sizeof(SMBCCTX)); + context = SMB_MALLOC_P(SMBCCTX); if (!context) { errno = ENOMEM; return NULL; @@ -4281,7 +4281,7 @@ ZERO_STRUCTP(context); - context->internal = malloc(sizeof(struct smbc_internal_data)); + context->internal = SMB_MALLOC_P(struct smbc_internal_data); if (!context->internal) { errno = ENOMEM; return NULL; @@ -4488,8 +4488,8 @@ */ user = getenv("USER"); /* walk around as "guest" if no username can be found */ - if (!user) context->user = strdup("guest"); - else context->user = strdup(user); + if (!user) context->user = SMB_STRDUP("guest"); + else context->user = SMB_STRDUP(user); } if (!context->netbios_name) { @@ -4498,14 +4498,14 @@ * back on constructing our netbios name from our hostname etc */ if (global_myname()) { - context->netbios_name = strdup(global_myname()); + context->netbios_name = SMB_STRDUP(global_myname()); } else { /* * Hmmm, I want to get hostname as well, but I am too lazy for the moment */ pid = sys_getpid(); - context->netbios_name = malloc(17); + context->netbios_name = SMB_MALLOC(17); if (!context->netbios_name) { errno = ENOMEM; return NULL; @@ -4518,11 +4518,11 @@ if (!context->workgroup) { if (lp_workgroup()) { - context->workgroup = strdup(lp_workgroup()); + context->workgroup = SMB_STRDUP(lp_workgroup()); } else { /* TODO: Think about a decent default workgroup */ - context->workgroup = strdup("samba"); + context->workgroup = SMB_STRDUP("samba"); } } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/libsmb_compat.c samba-3.0.9/source/libsmb/libsmb_compat.c --- samba-3.0.9-orig/source/libsmb/libsmb_compat.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/libsmb/libsmb_compat.c 2004-12-09 09:00:27.265599413 -0600 @@ -73,7 +73,7 @@ return -1; } - f = malloc(sizeof(struct smbc_compat_fdlist)); + f = SMB_MALLOC_P(struct smbc_compat_fdlist); if (!f) { errno = ENOMEM; return -1; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/namequery.c samba-3.0.9/source/libsmb/namequery.c --- samba-3.0.9-orig/source/libsmb/namequery.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/libsmb/namequery.c 2004-12-09 09:00:27.261600406 -0600 @@ -55,7 +55,7 @@ if (*num_names == 0) return NULL; - ret = (struct node_status *)malloc(sizeof(struct node_status)* (*num_names)); + ret = SMB_MALLOC_ARRAY(struct node_status,*num_names); if (!ret) return NULL; @@ -478,8 +478,8 @@ continue; } - tmp_ip_list = (struct in_addr *)Realloc( ip_list, sizeof( ip_list[0] ) - * ( (*count) + nmb2->answers->rdlength/6 ) ); + tmp_ip_list = SMB_REALLOC_ARRAY( ip_list, struct in_addr, + (*count) + nmb2->answers->rdlength/6 ); if (!tmp_ip_list) { DEBUG(0,("name_query: Realloc failed.\n")); @@ -655,7 +655,7 @@ return False; /* copy the ip address; port will be PORT_NONE */ - if ( (*return_iplist = (struct ip_service*)malloc(count*sizeof(struct ip_service))) == NULL ) { + if ( (*return_iplist = SMB_MALLOC_ARRAY(struct ip_service, count)) == NULL ) { DEBUG(0,("convert_ip2service: malloc failed for %d enetries!\n", count )); return False; } @@ -868,8 +868,8 @@ if ((name_type2 != -1) && (name_type != name_type2)) continue; - *return_iplist = (struct ip_service *)realloc((*return_iplist), - sizeof(struct ip_service) * ((*return_count)+1)); + *return_iplist = SMB_REALLOC_ARRAY((*return_iplist), struct ip_service, + (*return_count)+1); if ((*return_iplist) == NULL) { DEBUG(3,("resolve_lmhosts: malloc fail !\n")); @@ -919,7 +919,7 @@ if (((hp = sys_gethostbyname(name)) != NULL) && (hp->h_addr != NULL)) { struct in_addr return_ip; putip((char *)&return_ip,(char *)hp->h_addr); - *return_iplist = (struct ip_service *)malloc(sizeof(struct ip_service)); + *return_iplist = SMB_MALLOC_P(struct ip_service); if(*return_iplist == NULL) { DEBUG(3,("resolve_hosts: malloc fail !\n")); return False; @@ -958,7 +958,7 @@ return False; count = count_chars(list, ' ') + 1; - if ( (*return_iplist = malloc(count * sizeof(struct ip_service))) == NULL ) { + if ( (*return_iplist = SMB_MALLOC_ARRAY(struct ip_service, count)) == NULL ) { DEBUG(0,("resolve_hosts: malloc failed for %d entries\n", count )); return False; } @@ -1029,7 +1029,7 @@ if (allzeros || allones || is_address) { - if ( (*return_iplist = (struct ip_service *)malloc(sizeof(struct ip_service))) == NULL ) { + if ( (*return_iplist = SMB_MALLOC_P(struct ip_service)) == NULL ) { DEBUG(0,("internal_resolve_name: malloc fail !\n")); return False; } @@ -1333,8 +1333,7 @@ return False; } - if ( (return_iplist = (struct ip_service *) - malloc(num_addresses * sizeof(struct ip_service))) == NULL ) { + if ( (return_iplist = SMB_MALLOC_ARRAY(struct ip_service, num_addresses)) == NULL ) { DEBUG(3,("get_dc_list: malloc fail !\n")); return False; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/nmblib.c samba-3.0.9/source/libsmb/nmblib.c --- samba-3.0.9-orig/source/libsmb/nmblib.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/libsmb/nmblib.c 2004-12-09 09:00:27.275596929 -0600 @@ -354,7 +354,7 @@ { int i; - *recs = (struct res_rec *)malloc(sizeof(**recs)*count); + *recs = SMB_MALLOC_ARRAY(struct res_rec, count); if (!*recs) return(False); @@ -557,7 +557,7 @@ struct nmb_packet *copy_nmb; struct packet_struct *pkt_copy; - if(( pkt_copy = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) { + if(( pkt_copy = SMB_MALLOC_P(struct packet_struct)) == NULL) { DEBUG(0,("copy_nmb_packet: malloc fail.\n")); return NULL; } @@ -580,22 +580,19 @@ /* Now copy any resource records. */ if (nmb->answers) { - if((copy_nmb->answers = (struct res_rec *) - malloc(nmb->header.ancount * sizeof(struct res_rec))) == NULL) + if((copy_nmb->answers = SMB_MALLOC_ARRAY(struct res_rec,nmb->header.ancount)) == NULL) goto free_and_exit; memcpy((char *)copy_nmb->answers, (char *)nmb->answers, nmb->header.ancount * sizeof(struct res_rec)); } if (nmb->nsrecs) { - if((copy_nmb->nsrecs = (struct res_rec *) - malloc(nmb->header.nscount * sizeof(struct res_rec))) == NULL) + if((copy_nmb->nsrecs = SMB_MALLOC_ARRAY(struct res_rec, nmb->header.nscount)) == NULL) goto free_and_exit; memcpy((char *)copy_nmb->nsrecs, (char *)nmb->nsrecs, nmb->header.nscount * sizeof(struct res_rec)); } if (nmb->additional) { - if((copy_nmb->additional = (struct res_rec *) - malloc(nmb->header.arcount * sizeof(struct res_rec))) == NULL) + if((copy_nmb->additional = SMB_MALLOC_ARRAY(struct res_rec, nmb->header.arcount)) == NULL) goto free_and_exit; memcpy((char *)copy_nmb->additional, (char *)nmb->additional, nmb->header.arcount * sizeof(struct res_rec)); @@ -622,7 +619,7 @@ { struct packet_struct *pkt_copy; - if(( pkt_copy = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) { + if(( pkt_copy = SMB_MALLOC_P(struct packet_struct)) == NULL) { DEBUG(0,("copy_dgram_packet: malloc fail.\n")); return NULL; } @@ -700,7 +697,7 @@ struct packet_struct *p; BOOL ok=False; - p = (struct packet_struct *)malloc(sizeof(*p)); + p = SMB_MALLOC_P(struct packet_struct); if (!p) return(NULL); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/ntlmssp.c samba-3.0.9/source/libsmb/ntlmssp.c --- samba-3.0.9-orig/source/libsmb/ntlmssp.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/libsmb/ntlmssp.c 2004-12-09 09:00:27.270598171 -0600 @@ -766,7 +766,7 @@ mem_ctx = talloc_init("NTLMSSP context"); - *ntlmssp_state = talloc_zero(mem_ctx, sizeof(**ntlmssp_state)); + *ntlmssp_state = TALLOC_ZERO_P(mem_ctx, NTLMSSP_STATE); if (!*ntlmssp_state) { DEBUG(0,("ntlmssp_server_start: talloc failed!\n")); talloc_destroy(mem_ctx); @@ -1075,7 +1075,7 @@ mem_ctx = talloc_init("NTLMSSP Client context"); - *ntlmssp_state = talloc_zero(mem_ctx, sizeof(**ntlmssp_state)); + *ntlmssp_state = TALLOC_ZERO_P(mem_ctx, NTLMSSP_STATE); if (!*ntlmssp_state) { DEBUG(0,("ntlmssp_client_start: talloc failed!\n")); talloc_destroy(mem_ctx); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/samlogon_cache.c samba-3.0.9/source/libsmb/samlogon_cache.c --- samba-3.0.9-orig/source/libsmb/samlogon_cache.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/libsmb/samlogon_cache.c 2004-12-09 09:00:27.259600903 -0600 @@ -188,7 +188,7 @@ if ( data.dptr ) { - if ( (user = (NET_USER_INFO_3*)malloc(sizeof(NET_USER_INFO_3))) == NULL ) + if ( (user = SMB_MALLOC_P(NET_USER_INFO_3)) == NULL ) return NULL; prs_init( &ps, 0, mem_ctx, UNMARSHALL ); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/smb_signing.c samba-3.0.9/source/libsmb/smb_signing.c --- samba-3.0.9-orig/source/libsmb/smb_signing.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/libsmb/smb_signing.c 2004-12-09 09:00:27.256601648 -0600 @@ -54,7 +54,7 @@ } } - t = smb_xmalloc(sizeof(*t)); + t = SMB_XMALLOC_P(struct outstanding_packet_lookup); ZERO_STRUCTP(t); t->mid = mid; @@ -459,7 +459,7 @@ return False; } - data = smb_xmalloc(sizeof(*data)); + data = SMB_XMALLOC_P(struct smb_basic_signing_context); memset(data, '\0', sizeof(*data)); cli->sign_info.signing_context = data; @@ -509,7 +509,7 @@ if (!cli->sign_info.doing_signing || !data) return; - data->trans_info = smb_xmalloc(sizeof(struct trans_info_context)); + data->trans_info = SMB_XMALLOC_P(struct trans_info_context); ZERO_STRUCTP(data->trans_info); /* This ensures the sequence is pulled off the outstanding packet list */ @@ -982,7 +982,7 @@ if (!data) return; - data->trans_info = smb_xmalloc(sizeof(struct trans_info_context)); + data->trans_info = SMB_XMALLOC_P(struct trans_info_context); ZERO_STRUCTP(data->trans_info); data->trans_info->reply_seq_num = data->send_seq_num-1; @@ -1051,7 +1051,7 @@ srv_sign_info.doing_signing = True; - data = smb_xmalloc(sizeof(*data)); + data = SMB_XMALLOC_P(struct smb_basic_signing_context); memset(data, '\0', sizeof(*data)); srv_sign_info.signing_context = data; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/libsmb/spnego.c samba-3.0.9/source/libsmb/spnego.c --- samba-3.0.9-orig/source/libsmb/spnego.c 2004-11-15 21:03:20.000000000 -0600 +++ samba-3.0.9/source/libsmb/spnego.c 2004-12-09 09:00:27.268598668 -0600 @@ -42,12 +42,11 @@ asn1_start_tag(asn1, ASN1_CONTEXT(0)); asn1_start_tag(asn1, ASN1_SEQUENCE(0)); - token->mechTypes = malloc(sizeof(*token->mechTypes)); + token->mechTypes = SMB_MALLOC_P(char *); for (i = 0; !asn1->has_error && 0 < asn1_tag_remaining(asn1); i++) { token->mechTypes = - realloc(token->mechTypes, (i + 2) * - sizeof(*token->mechTypes)); + SMB_REALLOC_ARRAY(token->mechTypes, char *, i + 2); asn1_read_OID(asn1, token->mechTypes + i); } token->mechTypes[i] = NULL; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/locking/brlock.c samba-3.0.9/source/locking/brlock.c --- samba-3.0.9-orig/source/locking/brlock.c 2004-11-15 21:03:30.000000000 -0600 +++ samba-3.0.9/source/locking/brlock.c 2004-12-09 09:00:27.518536572 -0600 @@ -407,7 +407,7 @@ } /* no conflicts - add it to the list of locks */ - tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(*locks)); + tp = SMB_REALLOC(dbuf.dptr, dbuf.dsize + sizeof(*locks)); if (!tp) { status = NT_STATUS_NO_MEMORY; goto fail; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/locking/locking.c samba-3.0.9/source/locking/locking.c --- samba-3.0.9-orig/source/locking/locking.c 2004-11-15 21:03:30.000000000 -0600 +++ samba-3.0.9/source/locking/locking.c 2004-12-09 09:00:27.516537069 -0600 @@ -679,7 +679,7 @@ pstrcat(fname, fsp->fsp_name); size = sizeof(*data) + sizeof(share_mode_entry) + strlen(fname) + 1; - p = (char *)malloc(size); + p = (char *)SMB_MALLOC(size); if (!p) return False; data = (struct locking_data *)p; @@ -711,7 +711,7 @@ fsp->fsp_name, data->u.num_share_mode_entries )); size = dbuf.dsize + sizeof(share_mode_entry); - p = malloc(size); + p = SMB_MALLOC(size); if (!p) { SAFE_FREE(dbuf.dptr); return False; @@ -1161,7 +1161,7 @@ /* we'll need to create a new record */ size = sizeof(*data) + sizeof(deferred_open_entry) + strlen(fname) + 1; - p = (char *)malloc(size); + p = (char *)SMB_MALLOC(size); if (!p) return False; data = (struct deferred_open_data *)p; @@ -1193,7 +1193,7 @@ fname, data->u.num_deferred_open_entries )); size = dbuf.dsize + sizeof(deferred_open_entry); - p = malloc(size); + p = SMB_MALLOC(size); if (!p) { SAFE_FREE(dbuf.dptr); return False; diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/locking/posix.c samba-3.0.9/source/locking/posix.c --- samba-3.0.9-orig/source/locking/posix.c 2004-11-15 21:03:30.000000000 -0600 +++ samba-3.0.9/source/locking/posix.c 2004-12-09 09:00:27.513537814 -0600 @@ -102,7 +102,7 @@ dbuf = tdb_fetch(posix_pending_close_tdb, kbuf); - tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(int)); + tp = SMB_REALLOC(dbuf.dptr, dbuf.dsize + sizeof(int)); if (!tp) { DEBUG(0,("add_fd_to_close_entry: Realloc fail !\n")); SAFE_FREE(dbuf.dptr); @@ -371,7 +371,7 @@ pl.size = size; pl.lock_type = lock_type; - tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(pl)); + tp = SMB_REALLOC(dbuf.dptr, dbuf.dsize + sizeof(pl)); if (!tp) { DEBUG(0,("add_posix_lock_entry: Realloc fail !\n")); goto fail; @@ -896,8 +896,7 @@ | l_curr| | l_new | +-------+ +---------+ **********************************************/ - struct lock_list *l_new = (struct lock_list *)talloc(ctx, - sizeof(struct lock_list)); + struct lock_list *l_new = TALLOC_P(ctx, struct lock_list); if(l_new == NULL) { DEBUG(0,("posix_lock_list: talloc fail.\n")); @@ -1002,7 +1001,7 @@ return True; /* Not a fatal error. */ } - if ((ll = (struct lock_list *)talloc(l_ctx, sizeof(struct lock_list))) == NULL) { + if ((ll = TALLOC_P(l_ctx, struct lock_list)) == NULL) { DEBUG(0,("set_posix_lock: unable to talloc unlock list.\n")); talloc_destroy(l_ctx); return True; /* Not a fatal error. */ @@ -1148,7 +1147,7 @@ return True; /* Not a fatal error. */ } - if ((ul = (struct lock_list *)talloc(ul_ctx, sizeof(struct lock_list))) == NULL) { + if ((ul = TALLOC_P(ul_ctx, struct lock_list)) == NULL) { DEBUG(0,("release_posix_lock: unable to talloc unlock list.\n")); talloc_destroy(ul_ctx); return True; /* Not a fatal error. */ diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/modules/vfs_netatalk.c samba-3.0.9/source/modules/vfs_netatalk.c --- samba-3.0.9-orig/source/modules/vfs_netatalk.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/modules/vfs_netatalk.c 2004-12-09 09:00:27.253602393 -0600 @@ -126,16 +126,15 @@ } } - if (!(new_list = calloc(1, - (count == 0 ? 1 : count + 1) * sizeof(name_compare_entry)))) + if (!(new_list = SMB_CALLOC_ARRAY(name_compare_entry, (count == 0 ? 1 : count + 1)))) return; for (i = 0; i < count; i ++) { - new_list[i].name = strdup(cur_list[i].name); + new_list[i].name = SMB_STRDUP(cur_list[i].name); new_list[i].is_wild = cur_list[i].is_wild; } - new_list[i].name = strdup(APPLEDOUBLE); + new_list[i].name = SMB_STRDUP(APPLEDOUBLE); new_list[i].is_wild = False; free_namearray(*list); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/modules/vfs_recycle.c samba-3.0.9/source/modules/vfs_recycle.c --- samba-3.0.9-orig/source/modules/vfs_recycle.c 2004-11-15 21:03:21.000000000 -0600 +++ samba-3.0.9/source/modules/vfs_recycle.c 2004-12-09 09:00:27.251602890 -0600 @@ -215,12 +215,12 @@ mode = S_IRUSR | S_IWUSR | S_IXUSR; - tmp_str = strdup(dname); + tmp_str = SMB_STRDUP(dname); ALLOC_CHECK(tmp_str, done); tok_str = tmp_str; len = strlen(dname)+1; - new_dir = (char *)malloc(len + 1); + new_dir = (char *)SMB_MALLOC(len + 1); ALLOC_CHECK(new_dir, done); *new_dir = '\0'; @@ -389,11 +389,11 @@ base = strrchr(file_name, '/'); if (base == NULL) { base = file_name; - path_name = strdup("/"); + path_name = SMB_STRDUP("/"); ALLOC_CHECK(path_name, done); } else { - path_name = strdup(file_name); + path_name = SMB_STRDUP(file_name); ALLOC_CHECK(path_name, done); path_name[base - file_name] = '\0'; base++; @@ -422,7 +422,7 @@ if (recycle_keep_dir_tree(handle) == True) { asprintf(&temp_name, "%s/%s", repository, path_name); } else { - temp_name = strdup(repository); + temp_name = SMB_STRDUP(repository); } ALLOC_CHECK(temp_name, done); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/modules/vfs_shadow_copy.c samba-3.0.9/source/modules/vfs_shadow_copy.c --- samba-3.0.9-orig/source/modules/vfs_shadow_copy.c 2004-11-15 21:03:22.000000000 -0600 +++ samba-3.0.9/source/modules/vfs_shadow_copy.c 2004-12-09 09:00:27.254602145 -0600 @@ -82,7 +82,7 @@ return NULL; } - dirp = (shadow_copy_Dir *)malloc(sizeof(shadow_copy_Dir)); + dirp = SMB_MALLOC_P(shadow_copy_Dir); if (!dirp) { DEBUG(0,("shadow_copy_opendir: Out of memory\n")); SMB_VFS_NEXT_CLOSEDIR(handle,conn,p); @@ -108,7 +108,7 @@ DEBUG(10,("shadow_copy_opendir: not hide [%s]\n",d->d_name)); - r = (struct dirent *)Realloc(dirp->dirs,(dirp->num+1)*sizeof(struct dirent)); + r = SMB_REALLOC_ARRAY(dirp->dirs, struct dirent, dirp->num+1); if (!r) { DEBUG(0,("shadow_copy_opendir: Out of memory\n")); break; @@ -176,7 +176,7 @@ continue; } - tlabels = (SHADOW_COPY_LABEL *)talloc_realloc(shadow_copy_data->mem_ctx, + tlabels = (SHADOW_COPY_LABEL *)TALLOC_REALLOC(shadow_copy_data->mem_ctx, shadow_copy_data->labels, (shadow_copy_data->num_volumes+1)*sizeof(SHADOW_COPY_LABEL)); if (tlabels == NULL) { diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_become_lmb.c samba-3.0.9/source/nmbd/nmbd_become_lmb.c --- samba-3.0.9-orig/source/nmbd/nmbd_become_lmb.c 2004-11-15 21:03:25.000000000 -0600 +++ samba-3.0.9/source/nmbd/nmbd_become_lmb.c 2004-12-09 09:00:27.488544024 -0600 @@ -206,7 +206,7 @@ struct userdata_struct *userdata; size_t size = sizeof(struct userdata_struct) + sizeof(BOOL); - if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { + if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL) { DEBUG(0,("release_1d_name: malloc fail.\n")); return; } @@ -545,7 +545,7 @@ subrec->work_changed = True; /* Setup the userdata_struct. */ - if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { + if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL) { DEBUG(0,("become_local_master_browser: malloc fail.\n")); return; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_browserdb.c samba-3.0.9/source/nmbd/nmbd_browserdb.c --- samba-3.0.9-orig/source/nmbd/nmbd_browserdb.c 2004-11-15 21:03:26.000000000 -0600 +++ samba-3.0.9/source/nmbd/nmbd_browserdb.c 2004-12-09 09:00:27.494542533 -0600 @@ -87,7 +87,7 @@ struct browse_cache_record *browc; time_t now = time( NULL ); - browc = (struct browse_cache_record *)malloc( sizeof( *browc ) ); + browc = SMB_MALLOC_P(struct browse_cache_record); if( NULL == browc ) { DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") ); diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_browsesync.c samba-3.0.9/source/nmbd/nmbd_browsesync.c --- samba-3.0.9-orig/source/nmbd/nmbd_browsesync.c 2004-11-15 21:03:25.000000000 -0600 +++ samba-3.0.9/source/nmbd/nmbd_browsesync.c 2004-12-09 09:00:27.469548743 -0600 @@ -324,7 +324,7 @@ /* Setup the userdata_struct - this is copied so we can use a stack variable for this. */ - if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { + if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL) { DEBUG(0, ("find_domain_master_name_query_success: malloc fail.\n")); return; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_incomingrequests.c samba-3.0.9/source/nmbd/nmbd_incomingrequests.c --- samba-3.0.9-orig/source/nmbd/nmbd_incomingrequests.c 2004-11-15 21:03:25.000000000 -0600 +++ samba-3.0.9/source/nmbd/nmbd_incomingrequests.c 2004-12-09 09:00:27.471548246 -0600 @@ -516,7 +516,7 @@ if (namerec->data.num_ips == 1) { prdata = rdata; } else { - if ((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) { + if ((prdata = (char *)SMB_MALLOC( namerec->data.num_ips * 6 )) == NULL) { DEBUG(0,("process_name_query_request: malloc fail !\n")); return; } diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_namelistdb.c samba-3.0.9/source/nmbd/nmbd_namelistdb.c --- samba-3.0.9-orig/source/nmbd/nmbd_namelistdb.c 2004-11-15 21:03:25.000000000 -0600 +++ samba-3.0.9/source/nmbd/nmbd_namelistdb.c 2004-12-09 09:00:27.484545017 -0600 @@ -181,14 +181,14 @@ struct name_record *namerec; time_t time_now = time(NULL); - namerec = (struct name_record *)malloc( sizeof(*namerec) ); + namerec = SMB_MALLOC_P(struct name_record); if( NULL == namerec ) { DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) ); return( NULL ); } memset( (char *)namerec, '\0', sizeof(*namerec) ); - namerec->data.ip = (struct in_addr *)malloc( sizeof(struct in_addr) * num_ips ); + namerec->data.ip = SMB_MALLOC_ARRAY( struct in_addr, num_ips ); if( NULL == namerec->data.ip ) { DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) ); ZERO_STRUCTP(namerec); @@ -329,7 +329,7 @@ if( find_ip_in_name_record( namerec, new_ip ) ) return; - new_list = (struct in_addr *)malloc( (namerec->data.num_ips + 1) * sizeof(struct in_addr) ); + new_list = SMB_MALLOC_ARRAY( struct in_ad