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;i<num;i++) {
 			snprintf(shadow_copy_data->labels[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;i<len;i++) {
@@ -1533,7 +1533,7 @@
 	char *ret;
 	
 	n = strnlen(s, n);
-	ret = malloc(n+1);
+	ret = SMB_MALLOC(n+1);
 	if (!ret)
 		return NULL;
 	memcpy(ret, s, n);
@@ -1573,7 +1573,7 @@
 	
 	if (!string || !*string)
 		return NULL;
-	s = strdup(string);
+	s = SMB_STRDUP(string);
 	if (!s) {
 		DEBUG(0,("str_list_make: Unable to allocate memory"));
 		return NULL;
@@ -1587,7 +1587,7 @@
 	while (next_token(&str, tok, sep, sizeof(tok))) {		
 		if (num == lsize) {
 			lsize += S_LIST_ABS;
-			rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+			rlist = SMB_REALLOC_ARRAY(list, char *, lsize +1);
 			if (!rlist) {
 				DEBUG(0,("str_list_make: Unable to allocate memory"));
 				str_list_free(&list);
@@ -1598,7 +1598,7 @@
 			memset (&list[num], 0, ((sizeof(char**)) * (S_LIST_ABS +1)));
 		}
 		
-		list[num] = strdup(tok);
+		list[num] = SMB_STRDUP(tok);
 		if (!list[num]) {
 			DEBUG(0,("str_list_make: Unable to allocate memory"));
 			str_list_free(&list);
@@ -1628,7 +1628,7 @@
 	while (src[num]) {
 		if (num == lsize) {
 			lsize += S_LIST_ABS;
-			rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+			rlist = SMB_REALLOC_ARRAY(list, char *, lsize +1);
 			if (!rlist) {
 				DEBUG(0,("str_list_copy: Unable to re-allocate memory"));
 				str_list_free(&list);
@@ -1638,7 +1638,7 @@
 			memset (&list[num], 0, ((sizeof(char **)) * (S_LIST_ABS +1)));
 		}
 		
-		list[num] = strdup(src[num]);
+		list[num] = SMB_STRDUP(src[num]);
 		if (!list[num]) {
 			DEBUG(0,("str_list_copy: Unable to allocate memory"));
 			str_list_free(&list);
@@ -1740,7 +1740,7 @@
 			t = *list;
 			d = p -t;
 			if (ld) {
-				t = (char *) malloc(ls +ld +1);
+				t = (char *) SMB_MALLOC(ls +ld +1);
 				if (!t) {
 					DEBUG(0,("str_list_substitute: Unable to allocate memory"));
 					return False;
@@ -1863,7 +1863,7 @@
 		return 0;
 	
 	count = count_chars(ipstr_list, IPSTR_LIST_CHAR) + 1;
-	if ( (*ip_list = (struct ip_service*)malloc(count * sizeof(struct ip_service))) == NULL ) {
+	if ( (*ip_list = SMB_MALLOC_ARRAY(struct ip_service, count)) == NULL ) {
 		DEBUG(0,("ipstr_list_parse: malloc failed for %lu entries\n", (unsigned long)count));
 		return 0;
 	}
@@ -2011,7 +2011,7 @@
 	size_t out_cnt = 0;
 	size_t len = data.length;
 	size_t output_len = data.length * 2;
-	char *result = malloc(output_len); /* get us plenty of space */
+	char *result = SMB_MALLOC(output_len); /* get us plenty of space */
 
 	while (len-- && out_cnt < (data.length * 2) - 5) {
 		int c = (unsigned char) *(data.data++);
@@ -2072,11 +2072,11 @@
 	int new_len = strlen(right) + 1;
 
 	if (*left == NULL) {
-		*left = malloc(new_len);
+		*left = SMB_MALLOC(new_len);
 		*left[0] = '\0';
 	} else {
 		new_len += strlen(*left);
-		*left = Realloc(*left, new_len);
+		*left = SMB_REALLOC(*left, new_len);
 	}
 
 	if (*left == NULL)
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/lib/util_unistr.c samba-3.0.9/source/lib/util_unistr.c
--- samba-3.0.9-orig/source/lib/util_unistr.c	2004-11-15 21:03:19.000000000 -0600
+++ samba-3.0.9/source/lib/util_unistr.c	2004-12-09 09:00:27.215611832 -0600
@@ -61,7 +61,7 @@
 	   not available */
 	if (!upcase_table) {
 		DEBUG(1,("creating lame upcase table\n"));
-		upcase_table = malloc(0x20000);
+		upcase_table = SMB_MALLOC(0x20000);
 		for (i=0;i<0x10000;i++) {
 			smb_ucs2_t v;
 			SSVAL(&v, 0, i);
@@ -76,7 +76,7 @@
 
 	if (!lowcase_table) {
 		DEBUG(1,("creating lame lowcase table\n"));
-		lowcase_table = malloc(0x20000);
+		lowcase_table = SMB_MALLOC(0x20000);
 		for (i=0;i<0x10000;i++) {
 			smb_ucs2_t v;
 			SSVAL(&v, 0, i);
@@ -175,7 +175,7 @@
 	if (valid_table) free(valid_table);
 
 	DEBUG(2,("creating default valid table\n"));
-	valid_table = malloc(0x10000);
+	valid_table = SMB_MALLOC(0x10000);
 	for (i=0;i<128;i++)
 		valid_table[i] = isalnum(i) || strchr(allowed,i);
 	
@@ -302,7 +302,7 @@
 	char *s;
 	int maxlen = (str->uni_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_addr, namerec->data.num_ips + 1);
 	if( NULL == new_list ) {
 		DEBUG(0,("add_ip_to_name_record: Malloc fail !\n"));
 		return;
@@ -460,7 +460,7 @@
 		/* Create an IP list containing all our known subnets. */
 
 		num_ips = iface_count();
-		iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) );
+		iplist = SMB_MALLOC_ARRAY( struct in_addr, num_ips);
 		if( NULL == iplist ) {
 			DEBUG(0,("add_samba_names_to_subnet: Malloc fail !\n"));
 			return;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_nameregister.c samba-3.0.9/source/nmbd/nmbd_nameregister.c
--- samba-3.0.9-orig/source/nmbd/nmbd_nameregister.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/nmbd/nmbd_nameregister.c	2004-12-09 09:00:27.490543527 -0600
@@ -306,7 +306,7 @@
 	struct in_addr wins_ip = wins_srv_ip_tag(tag, ip);
 	fstring ip_str;
 
-	userdata = (struct userdata_struct *)malloc(sizeof(*userdata) + strlen(tag) + 1);
+	userdata = (struct userdata_struct *)SMB_MALLOC(sizeof(*userdata) + strlen(tag) + 1);
 	if (!userdata) {
 		DEBUG(0,("Failed to allocate userdata structure!\n"));
 		return;
@@ -423,7 +423,7 @@
 	for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) )
 		num_ips++;
 	
-	if((ip_list = (struct in_addr *)malloc(num_ips * sizeof(struct in_addr)))==NULL) {
+	if((ip_list = SMB_MALLOC_ARRAY(struct in_addr, num_ips))==NULL) {
 		DEBUG(0,("multihomed_register_name: malloc fail !\n"));
 		return;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_packets.c samba-3.0.9/source/nmbd/nmbd_packets.c
--- samba-3.0.9-orig/source/nmbd/nmbd_packets.c	2004-11-15 21:03:26.000000000 -0600
+++ samba-3.0.9/source/nmbd/nmbd_packets.c	2004-12-09 09:00:27.497541788 -0600
@@ -184,7 +184,7 @@
 	struct nmb_packet *nmb = NULL;
 
 	/* Allocate the packet_struct we will return. */
-	if((packet = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) {
+	if((packet = SMB_MALLOC_P(struct packet_struct)) == NULL) {
 		DEBUG(0,("create_and_init_netbios_packet: malloc fail (1) for packet struct.\n"));
 		return NULL;
 	}
@@ -230,7 +230,7 @@
 {
 	struct nmb_packet *nmb = &packet->packet.nmb;
 
-	if((nmb->additional = (struct res_rec *)malloc(sizeof(struct res_rec))) == NULL) {
+	if((nmb->additional = SMB_MALLOC_P(struct res_rec)) == NULL) {
 		DEBUG(0,("initiate_name_register_packet: malloc fail for additional record.\n"));
 		return False;
 	}
@@ -534,7 +534,7 @@
 	DEBUG(6,("Refreshing name %s IP %s with WINS server %s using tag '%s'\n",
 		 nmb_namestr(nmbname), ip_str, inet_ntoa(wins_ip), tag));
 
-	userdata = (struct userdata_struct *)malloc(sizeof(*userdata) + strlen(tag) + 1);
+	userdata = (struct userdata_struct *)SMB_MALLOC(sizeof(*userdata) + strlen(tag) + 1);
 	if (!userdata) {
 		DEBUG(0,("Failed to allocate userdata structure!\n"));
 		return;
@@ -1645,7 +1645,7 @@
 	struct subnet_record *subrec = NULL;
 	int count = 0;
 	int num = 0;
-	fd_set *pset = (fd_set *)malloc(sizeof(fd_set));
+	fd_set *pset = SMB_MALLOC_P(fd_set);
 
 	if(pset == NULL) {
 		DEBUG(0,("create_listen_fdset: malloc fail !\n"));
@@ -1662,7 +1662,7 @@
 		return True;
 	}
 
-	if((sock_array = (int *)malloc(((count*2) + 2)*sizeof(int))) == NULL) {
+	if((sock_array = SMB_MALLOC_ARRAY(int, (count*2) + 2)) == NULL) {
 		DEBUG(0,("create_listen_fdset: malloc fail for socket array.\n"));
 		return True;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_processlogon.c samba-3.0.9/source/nmbd/nmbd_processlogon.c
--- samba-3.0.9-orig/source/nmbd/nmbd_processlogon.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/nmbd/nmbd_processlogon.c	2004-12-09 09:00:27.482545514 -0600
@@ -577,8 +577,7 @@
 					return;
 				}
 
-				db_info = (struct sam_database_info *)
-						malloc(sizeof(struct sam_database_info) * db_count);
+				db_info = SMB_MALLOC_ARRAY(struct sam_database_info, db_count);
 
 				if (db_info == NULL) {
 					DEBUG(3, ("out of memory allocating info for %d databases\n", db_count));
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_responserecordsdb.c samba-3.0.9/source/nmbd/nmbd_responserecordsdb.c
--- samba-3.0.9-orig/source/nmbd/nmbd_responserecordsdb.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/nmbd/nmbd_responserecordsdb.c	2004-12-09 09:00:27.492543030 -0600
@@ -105,7 +105,7 @@
 	struct response_record *rrec;
 	struct nmb_packet *nmb = &p->packet.nmb;
 
-	if (!(rrec = (struct response_record *)malloc(sizeof(*rrec)))) {
+	if (!(rrec = SMB_MALLOC_P(struct response_record))) {
 		DEBUG(0,("make_response_queue_record: malloc fail for response_record.\n"));
 		return NULL;
 	}
@@ -133,7 +133,7 @@
 		} else {
 			/* Primitive userdata, do a memcpy. */
 			if((rrec->userdata = (struct userdata_struct *)
-					malloc(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL) {
+					SMB_MALLOC(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL) {
 				DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n"));
 				ZERO_STRUCTP(rrec);
 				SAFE_FREE(rrec);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_serverlistdb.c samba-3.0.9/source/nmbd/nmbd_serverlistdb.c
--- samba-3.0.9-orig/source/nmbd/nmbd_serverlistdb.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/nmbd/nmbd_serverlistdb.c	2004-12-09 09:00:27.480546011 -0600
@@ -137,7 +137,7 @@
 		return NULL;
 	}
   
-	if((servrec = (struct server_record *)malloc(sizeof(*servrec))) == NULL) {
+	if((servrec = SMB_MALLOC_P(struct server_record)) == NULL) {
 		DEBUG(0,("create_server_entry_on_workgroup: malloc fail !\n"));
 		return NULL;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_subnetdb.c samba-3.0.9/source/nmbd/nmbd_subnetdb.c
--- samba-3.0.9-orig/source/nmbd/nmbd_subnetdb.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/nmbd/nmbd_subnetdb.c	2004-12-09 09:00:27.475547253 -0600
@@ -147,7 +147,7 @@
 		set_socket_options(dgram_sock,"SO_BROADCAST");
 	}
 
-	subrec = (struct subnet_record *)malloc(sizeof(*subrec));
+	subrec = SMB_MALLOC_P(struct subnet_record);
 	if (!subrec) {
 		DEBUG(0,("make_subnet: malloc fail !\n"));
 		close(nmb_sock);
@@ -160,7 +160,7 @@
 			namelist_entry_compare,
 			ubi_trOVERWRITE );
 
-	if((subrec->subnet_name = strdup(name)) == NULL) {
+	if((subrec->subnet_name = SMB_STRDUP(name)) == NULL) {
 		DEBUG(0,("make_subnet: malloc fail for subnet name !\n"));
 		close(nmb_sock);
 		close(dgram_sock);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_synclists.c samba-3.0.9/source/nmbd/nmbd_synclists.c
--- samba-3.0.9-orig/source/nmbd/nmbd_synclists.c	2004-11-15 21:03:26.000000000 -0600
+++ samba-3.0.9/source/nmbd/nmbd_synclists.c	2004-12-09 09:00:27.499541291 -0600
@@ -143,7 +143,7 @@
 		return;
 	}
 
-	s = (struct sync_record *)malloc(sizeof(*s));
+	s = SMB_MALLOC_P(struct sync_record);
 	if (!s) goto done;
 
 	ZERO_STRUCTP(s);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_winsproxy.c samba-3.0.9/source/nmbd/nmbd_winsproxy.c
--- samba-3.0.9-orig/source/nmbd/nmbd_winsproxy.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/nmbd/nmbd_winsproxy.c	2004-12-09 09:00:27.485544769 -0600
@@ -59,7 +59,7 @@
 	if(num_ips == 1) {
 		iplist = &ip;
 	} else {
-		if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL) {
+		if((iplist = SMB_MALLOC_ARRAY( struct in_addr, num_ips )) == NULL) {
 			DEBUG(0,("wins_proxy_name_query_request_success: malloc fail !\n"));
 			return;
 		}
@@ -131,7 +131,7 @@
 static struct userdata_struct *wins_proxy_userdata_copy_fn(struct userdata_struct *userdata)
 {
 	struct packet_struct *p, *copy_of_p;
-	struct userdata_struct *new_userdata = (struct userdata_struct *)malloc( userdata->userdata_len );
+	struct userdata_struct *new_userdata = (struct userdata_struct *)SMB_MALLOC( userdata->userdata_len );
 
 	if(new_userdata == NULL)
 		return NULL;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_winsserver.c samba-3.0.9/source/nmbd/nmbd_winsserver.c
--- samba-3.0.9-orig/source/nmbd/nmbd_winsserver.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/nmbd/nmbd_winsserver.c	2004-12-09 09:00:27.478546507 -0600
@@ -318,7 +318,7 @@
 		}
 
 		/* Allocate the space for the ip_list. */
-		if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) {
+		if((ip_list = SMB_MALLOC_ARRAY( struct in_addr, num_ips)) == NULL) {
 			DEBUG(0,("initialise_wins: Malloc fail !\n"));
 			return False;
 		}
@@ -1379,7 +1379,7 @@
 		return;
 	}
 
-	if((prdata = (char *)malloc( num_ips * 6 )) == NULL) {
+	if((prdata = (char *)SMB_MALLOC( num_ips * 6 )) == NULL) {
 		DEBUG(0,("process_wins_dmb_query_request: Malloc fail !.\n"));
 		return;
 	}
@@ -1442,7 +1442,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,("send_wins_name_query_response: malloc fail !\n"));
 				return;
 			}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nmbd/nmbd_workgroupdb.c samba-3.0.9/source/nmbd/nmbd_workgroupdb.c
--- samba-3.0.9-orig/source/nmbd/nmbd_workgroupdb.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/nmbd/nmbd_workgroupdb.c	2004-12-09 09:00:27.473547749 -0600
@@ -71,7 +71,7 @@
 	struct subnet_record *subrec;
 	int t = -1;
   
-	if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) {
+	if((work = SMB_MALLOC_P(struct work_record)) == NULL) {
 		DEBUG(0,("create_workgroup: malloc fail !\n"));
 		return NULL;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/wb_client.c samba-3.0.9/source/nsswitch/wb_client.c
--- samba-3.0.9-orig/source/nsswitch/wb_client.c	2004-11-15 21:03:17.000000000 -0600
+++ samba-3.0.9/source/nsswitch/wb_client.c	2004-12-09 09:00:27.135631702 -0600
@@ -326,7 +326,7 @@
 		/* Add group to list if necessary */
 
 		if (!is_member) {
-			tgr = (gid_t *)Realloc(groups, sizeof(gid_t) * ngroups + 1);
+			tgr = SMB_REALLOC_ARRAY(groups, gid_t, ngroups + 1);
 			
 			if (!tgr) {
 				errno = ENOMEM;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_acct.c samba-3.0.9/source/nsswitch/winbindd_acct.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_acct.c	2004-11-15 21:03:18.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_acct.c	2004-12-09 09:00:27.164624499 -0600
@@ -219,7 +219,7 @@
 		if ( num_gr_members ) {
 			fstring buffer;
 			
-			gr_members = (char**)smb_xmalloc(sizeof(char*)*(num_gr_members+1));
+			gr_members = SMB_XMALLOC_ARRAY(char*, num_gr_members+1);
 			
 			i = 0;
 			while ( next_token(&str, buffer, ",", sizeof(buffer)) && i<num_gr_members ) {
@@ -284,7 +284,7 @@
 			member = grp->gr_mem[num_members];
 		}
 		
-		gr_mem_str = smb_xmalloc(size);
+		gr_mem_str = SMB_XMALLOC_ARRAY(char, size);
 	
 		for ( i=0; i<num_members; i++ ) {
 			snprintf( &gr_mem_str[idx], size-idx, "%s,", grp->gr_mem[i] );
@@ -295,7 +295,7 @@
 	}
 	else {
 		/* no members */
-		gr_mem_str = smb_xmalloc(sizeof(fstring));
+		gr_mem_str = SMB_XMALLOC_ARRAY(char, sizeof(fstring));
 		fstrcpy( gr_mem_str, "" );
 	}
 
@@ -639,7 +639,7 @@
 	}
 	
 	/* add one new slot and keep an extra for the terminating NULL */
-	members = Realloc( grp->gr_mem, (grp->num_gr_mem+2)*sizeof(char*) );
+	members = SMB_REALLOC_ARRAY( grp->gr_mem, char *, grp->num_gr_mem+2);
 	if ( !members )
 		return False;
 		
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_ads.c samba-3.0.9/source/nsswitch/winbindd_ads.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_ads.c	2004-11-15 21:03:17.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_ads.c	2004-12-09 09:00:27.141630212 -0600
@@ -72,7 +72,7 @@
 	ads->auth.password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
 
 	SAFE_FREE(ads->auth.realm);
-	ads->auth.realm = strdup(lp_realm());
+	ads->auth.realm = SMB_STRDUP(lp_realm());
 
 	status = ads_connect(ads);
 	if (!ADS_ERR_OK(status) || !ads->config.realm) {
@@ -146,7 +146,7 @@
 		goto done;
 	}
 
-	(*info) = talloc_zero(mem_ctx, count * sizeof(**info));
+	(*info) = TALLOC_ZERO_ARRAY(mem_ctx, WINBIND_USERINFO, count);
 	if (!*info) {
 		status = NT_STATUS_NO_MEMORY;
 		goto done;
@@ -179,7 +179,7 @@
 			continue;
 		}
 
-		sid2 = talloc(mem_ctx, sizeof(*sid2));
+		sid2 = TALLOC_P(mem_ctx, DOM_SID);
 		if (!sid2) {
 			status = NT_STATUS_NO_MEMORY;
 			goto done;
@@ -248,7 +248,7 @@
 		goto done;
 	}
 
-	(*info) = talloc_zero(mem_ctx, count * sizeof(**info));
+	(*info) = TALLOC_ZERO_ARRAY(mem_ctx, struct acct_info, count);
 	if (!*info) {
 		status = NT_STATUS_NO_MEMORY;
 		goto done;
@@ -421,7 +421,7 @@
 		goto done;
 	}
 	
-	sid2 = talloc(mem_ctx, sizeof(*sid2));
+	sid2 = TALLOC_P(mem_ctx, DOM_SID);
 	if (!sid2) {
 		status = NT_STATUS_NO_MEMORY;
 		goto done;
@@ -501,7 +501,7 @@
 		goto done;
 	}
 	
-	(*user_gids) = talloc_zero(mem_ctx, sizeof(**user_gids) * (count + 1));
+	(*user_gids) = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID *, count + 1);
 	(*user_gids)[0] = primary_group;
 	
 	*num_groups = 1;
@@ -516,7 +516,7 @@
 		
 		if (sid_equal(&group_sid, primary_group)) continue;
 		
-		(*user_gids)[*num_groups] = talloc(mem_ctx, sizeof(***user_gids));
+		(*user_gids)[*num_groups] = TALLOC_P(mem_ctx, DOM_SID);
 		if (!(*user_gids)[*num_groups]) {
 			status = NT_STATUS_NO_MEMORY;
 			goto done;
@@ -610,7 +610,7 @@
 					     num_groups, user_gids);
 	}
 
-	(*user_gids) = talloc_zero(mem_ctx, sizeof(**user_gids) * (count + 1));
+	(*user_gids) = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID *, count + 1);
 	(*user_gids)[0] = primary_group;
 	
 	*num_groups = 1;
@@ -618,7 +618,7 @@
 	for (i=0;i<count;i++) {
 		if (sid_equal(&sids[i], primary_group)) continue;
 		
-		(*user_gids)[*num_groups] = talloc(mem_ctx, sizeof(***user_gids));
+		(*user_gids)[*num_groups] = TALLOC_P(mem_ctx, DOM_SID);
 		if (!(*user_gids)[*num_groups]) {
 			status = NT_STATUS_NO_MEMORY;
 			goto done;
@@ -685,7 +685,7 @@
 	members = NULL;
 	num_members = 0;
 
-	attrs = talloc(mem_ctx, 3 * sizeof(*attrs));
+	attrs = TALLOC_ARRAY(mem_ctx, const char *, 3);
 	attrs[1] = talloc_strdup(mem_ctx, "usnChanged");
 	attrs[2] = NULL;
 		
@@ -751,9 +751,9 @@
 	   the problem is that the members are in the form of distinguised names
 	*/
 
-	(*sid_mem) = talloc_zero(mem_ctx, sizeof(**sid_mem) * num_members);
-	(*name_types) = talloc_zero(mem_ctx, sizeof(**name_types) * num_members);
-	(*names) = talloc_zero(mem_ctx, sizeof(**names) * num_members);
+	(*sid_mem) = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID *, num_members);
+	(*name_types) = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_members);
+	(*names) = TALLOC_ZERO_ARRAY(mem_ctx, char *, num_members);
 
 	for (i=0;i<num_members;i++) {
 		uint32 name_type;
@@ -763,7 +763,7 @@
 		if (dn_lookup(ads, mem_ctx, members[i], &name, &name_type, &sid)) {
 		    (*names)[*num_names] = name;
 		    (*name_types)[*num_names] = name_type;
-		    (*sid_mem)[*num_names] = talloc(mem_ctx, sizeof(***sid_mem));
+		    (*sid_mem)[*num_names] = TALLOC_P(mem_ctx, DOM_SID);
 		    if (!(*sid_mem)[*num_names]) {
 			    status = NT_STATUS_NO_MEMORY;
 			    goto done;
@@ -850,19 +850,19 @@
 	
 		/* Allocate memory for trusted domain names and sids */
 
-		if ( !(*names = (char **)talloc(mem_ctx, sizeof(char *) * count)) ) {
+		if ( !(*names = TALLOC_ARRAY(mem_ctx, char *, count)) ) {
 			DEBUG(0, ("trusted_domains: out of memory\n"));
 			result = NT_STATUS_NO_MEMORY;
 			goto done;
 		}
 
-		if ( !(*alt_names = (char **)talloc(mem_ctx, sizeof(char *) * count)) ) {
+		if ( !(*alt_names = TALLOC_ARRAY(mem_ctx, char *, count)) ) {
 			DEBUG(0, ("trusted_domains: out of memory\n"));
 			result = NT_STATUS_NO_MEMORY;
 			goto done;
 		}
 
-		if ( !(*dom_sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * count)) ) {
+		if ( !(*dom_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, count)) ) {
 			DEBUG(0, ("trusted_domains: out of memory\n"));
 			result = NT_STATUS_NO_MEMORY;
 			goto done;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd.c samba-3.0.9/source/nsswitch/winbindd.c
--- samba-3.0.9-orig/source/nsswitch/winbindd.c	2004-11-15 21:03:17.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd.c	2004-12-09 09:00:27.148628473 -0600
@@ -357,8 +357,7 @@
 	
 	/* Create new connection structure */
 	
-	if ((state = (struct winbindd_cli_state *) 
-             malloc(sizeof(*state))) == NULL)
+	if ((state = SMB_MALLOC_P(struct winbindd_cli_state)) == NULL)
 		return;
 	
 	ZERO_STRUCTP(state);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_cache.c samba-3.0.9/source/nsswitch/winbindd_cache.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_cache.c	2004-11-15 21:03:18.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_cache.c	2004-12-09 09:00:27.162624996 -0600
@@ -136,7 +136,7 @@
 	if (ret)
 		return ret;
 	
-	ret = smb_xmalloc(sizeof(*ret));
+	ret = SMB_XMALLOC_P(struct winbind_cache);
 	ZERO_STRUCTP(ret);
 
 	wcache = ret;
@@ -209,7 +209,7 @@
 		smb_panic("centry_string");
 	}
 
-	ret = talloc(mem_ctx, len+1);
+	ret = TALLOC(mem_ctx, len+1);
 	if (!ret) {
 		smb_panic("centry_string out of memory\n");
 	}
@@ -227,7 +227,7 @@
 	DOM_SID *sid;
 	char *sid_string;
 
-	sid = talloc(mem_ctx, sizeof(*sid));
+	sid = TALLOC_P(mem_ctx, DOM_SID);
 	if (!sid)
 		return NULL;
 	
@@ -450,7 +450,7 @@
 		return NULL;
 	}
 
-	centry = smb_xmalloc(sizeof(*centry));
+	centry = SMB_XMALLOC_P(struct cache_entry);
 	centry->data = (unsigned char *)data.dptr;
 	centry->len = data.dsize;
 	centry->ofs = 0;
@@ -501,7 +501,7 @@
 	if (centry->len - centry->ofs >= len)
 		return;
 	centry->len *= 2;
-	p = realloc(centry->data, centry->len);
+	p = SMB_REALLOC(centry->data, centry->len);
 	if (!p) {
 		DEBUG(0,("out of memory: needed %d bytes in centry_expand\n", centry->len));
 		smb_panic("out of memory in centry_expand");
@@ -568,10 +568,10 @@
 	if (!wcache->tdb)
 		return NULL;
 
-	centry = smb_xmalloc(sizeof(*centry));
+	centry = SMB_XMALLOC_P(struct cache_entry);
 
 	centry->len = 8192; /* reasonable default */
-	centry->data = smb_xmalloc(centry->len);
+	centry->data = SMB_XMALLOC_ARRAY(char, centry->len);
 	centry->ofs = 0;
 	centry->sequence_number = domain->sequence_number;
 	centry_put_uint32(centry, NT_STATUS_V(status));
@@ -684,7 +684,7 @@
 	if (*num_entries == 0)
 		goto do_cached;
 
-	(*info) = talloc(mem_ctx, sizeof(**info) * (*num_entries));
+	(*info) = TALLOC_ARRAY(mem_ctx, WINBIND_USERINFO, *num_entries);
 	if (! (*info))
 		smb_panic("query_user_list out of memory");
 	for (i=0; i<(*num_entries); i++) {
@@ -793,7 +793,7 @@
 	if (*num_entries == 0)
 		goto do_cached;
 
-	(*info) = talloc(mem_ctx, sizeof(**info) * (*num_entries));
+	(*info) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_entries);
 	if (! (*info))
 		smb_panic("enum_dom_groups out of memory");
 	for (i=0; i<(*num_entries); i++) {
@@ -866,7 +866,7 @@
 	if (*num_entries == 0)
 		goto do_cached;
 
-	(*info) = talloc(mem_ctx, sizeof(**info) * (*num_entries));
+	(*info) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_entries);
 	if (! (*info))
 		smb_panic("enum_dom_groups out of memory");
 	for (i=0; i<(*num_entries); i++) {
@@ -1156,7 +1156,7 @@
 	if (*num_groups == 0)
 		goto do_cached;
 
-	(*user_gids) = talloc(mem_ctx, sizeof(**user_gids) * (*num_groups));
+	(*user_gids) = TALLOC_ARRAY(mem_ctx, DOM_SID *, *num_groups);
 	if (! (*user_gids))
 		smb_panic("lookup_usergroups out of memory");
 	for (i=0; i<(*num_groups); i++) {
@@ -1227,9 +1227,9 @@
 	if (*num_names == 0)
 		goto do_cached;
 
-	(*sid_mem) = talloc(mem_ctx, sizeof(**sid_mem) * (*num_names));
-	(*names) = talloc(mem_ctx, sizeof(**names) * (*num_names));
-	(*name_types) = talloc(mem_ctx, sizeof(**name_types) * (*num_names));
+	(*sid_mem) = TALLOC_ARRAY(mem_ctx, DOM_SID *, *num_names);
+	(*names) = TALLOC_ARRAY(mem_ctx, char *, *num_names);
+	(*name_types) = TALLOC_ARRAY(mem_ctx, uint32, *num_names);
 
 	if (! (*sid_mem) || ! (*names) || ! (*name_types)) {
 		smb_panic("lookup_groupmem out of memory");
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_cm.c samba-3.0.9/source/nsswitch/winbindd_cm.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_cm.c	2004-11-15 21:03:17.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_cm.c	2004-12-09 09:00:27.138630957 -0600
@@ -489,7 +489,7 @@
 	struct winbindd_cm_conn *conn;
 	NTSTATUS result;
 
-	if (!(conn = malloc(sizeof(*conn))))
+	if (!(conn = SMB_MALLOC_P(struct winbindd_cm_conn)))
 		return NT_STATUS_NO_MEMORY;
 		
 	ZERO_STRUCTP(conn);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_dual.c samba-3.0.9/source/nsswitch/winbindd_dual.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_dual.c	2004-11-15 21:03:18.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_dual.c	2004-12-09 09:00:27.152627480 -0600
@@ -117,7 +117,7 @@
 
 	if (!background_process) return;
 
-	list = malloc(sizeof(*list));
+	list = SMB_MALLOC_P(struct dual_list);
 	if (!list) return;
 
 	list->next = NULL;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_group.c samba-3.0.9/source/nsswitch/winbindd_group.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_group.c	2004-11-15 21:03:18.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_group.c	2004-12-09 09:00:27.158625990 -0600
@@ -47,7 +47,7 @@
 	for ( i=0; i<num_members; i++ )
 		len += strlen(members[i])+1;
 
-	*buffer = (char*)smb_xmalloc(len);
+	*buffer = SMB_XMALLOC_ARRAY(char, len);
 	for ( i=0; i<num_members; i++ ) {
 		snprintf( &(*buffer)[idx], len-idx, "%s,", members[i]);
 		idx += strlen(members[i])+1;
@@ -194,7 +194,7 @@
 	/* Allocate buffer */
 
 	if (!buf && buf_len != 0) {
-		if (!(buf = malloc(buf_len))) {
+		if (!(buf = SMB_MALLOC(buf_len))) {
 			DEBUG(1, ("out of memory\n"));
 			result = False;
 			goto done;
@@ -457,8 +457,7 @@
 		}
 						
 		
-		if ((domain_state = (struct getent_state *)
-		     malloc(sizeof(struct getent_state))) == NULL) {
+		if ((domain_state = SMB_MALLOC_P(struct getent_state)) == NULL) {
 			DEBUG(1, ("winbindd_setgrent: malloc failed for domain_state!\n"));
 			return WINBINDD_ERROR;
 		}
@@ -542,7 +541,7 @@
 	/* Copy entries into return buffer */
 
 	if (num_entries) {
-		if ( !(name_list = malloc(sizeof(struct acct_info) * num_entries)) ) {
+		if ( !(name_list = SMB_MALLOC_ARRAY(struct acct_info, num_entries)) ) {
 			DEBUG(0,("get_sam_group_entries: Failed to malloc memory for %d domain groups!\n", 
 				num_entries));
 			result = False;
@@ -573,7 +572,7 @@
 		/* Copy entries into return buffer */
 
 		if ( num_entries ) {
-			if ( !(tmp_name_list = Realloc( name_list, sizeof(struct acct_info) * (ent->num_sam_entries+num_entries))) )
+			if ( !(tmp_name_list = SMB_REALLOC_ARRAY( name_list, struct acct_info, ent->num_sam_entries+num_entries)) )
 			{
 				DEBUG(0,("get_sam_group_entries: Failed to realloc more memory for %d local groups!\n", 
 					num_entries));
@@ -625,8 +624,7 @@
 
 	num_groups = MIN(MAX_GETGRENT_GROUPS, state->request.data.num_entries);
 
-	if ((state->response.extra_data = 
-	     malloc(num_groups * sizeof(struct winbindd_gr))) == NULL)
+	if ((state->response.extra_data = SMB_MALLOC_ARRAY(struct winbindd_gr, num_groups)) == NULL)
 		return WINBINDD_ERROR;
 
 	memset(state->response.extra_data, '\0',
@@ -746,9 +744,7 @@
 
 		if (result) {
 			/* Append to group membership list */
-			new_gr_mem_list = Realloc(
-				gr_mem_list,
-				gr_mem_list_len + gr_mem_len);
+			new_gr_mem_list = SMB_REALLOC( gr_mem_list, gr_mem_list_len + gr_mem_len);
 
 			if (!new_gr_mem_list && (group_list[group_list_ndx].num_gr_mem != 0)) {
 				DEBUG(0, ("out of memory\n"));
@@ -799,7 +795,7 @@
 	if (group_list_ndx == 0)
 		goto done;
 
-	new_extra_data = Realloc(
+	new_extra_data = SMB_REALLOC(
 		state->response.extra_data,
 		group_list_ndx * sizeof(struct winbindd_gr) + gr_mem_list_len);
 
@@ -880,7 +876,7 @@
 		
 		/* Allocate some memory for extra data.  Note that we limit
 		   account names to sizeof(fstring) = 128 characters.  */		
-                ted = Realloc(extra_data, sizeof(fstring) * total_entries);
+                ted = SMB_REALLOC(extra_data, sizeof(fstring) * total_entries);
  
 		if (!ted) {
 			DEBUG(0,("failed to enlarge buffer!\n"));
@@ -1156,12 +1152,12 @@
 			return;
 	}
 
-	*sids = talloc_realloc(mem_ctx, *sids, sizeof(**sids) * (*num_sids+1));
+	*sids = TALLOC_REALLOC_ARRAY(mem_ctx, *sids, DOM_SID *, *num_sids+1);
 
 	if (*sids == NULL)
 		return;
 
-	(*sids)[*num_sids] = talloc(mem_ctx, sizeof(DOM_SID));
+	(*sids)[*num_sids] = TALLOC_P(mem_ctx, DOM_SID);
 	sid_copy((*sids)[*num_sids], sid);
 	*num_sids += 1;
 	return;
@@ -1264,7 +1260,7 @@
 	}
 
 	/* build the reply */
-	ret = malloc(ret_size);
+	ret = SMB_MALLOC(ret_size);
 	if (!ret) goto done;
 	ofs = 0;
 	for (i = 0; i < num_groups; i++) {
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_misc.c samba-3.0.9/source/nsswitch/winbindd_misc.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_misc.c	2004-11-15 21:03:17.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_misc.c	2004-12-09 09:00:27.136631454 -0600
@@ -128,7 +128,7 @@
 		/* Add domain to list */
 
 		total_entries++;
-		ted = Realloc(extra_data, sizeof(fstring) * 
+		ted = SMB_REALLOC(extra_data, sizeof(fstring) * 
                               total_entries);
 
 		if (!ted) {
@@ -168,7 +168,7 @@
 	state->request.domain_name[sizeof(state->request.domain_name)-1]='\0';	
 	which_domain = state->request.domain_name;
 
-	extra_data = strdup("");
+	extra_data = SMB_STRDUP("");
 
 	/* this makes for a very simple data format, and is easily parsable as well
 	   if that is ever needed */
@@ -296,7 +296,7 @@
 
 	DEBUG(3, ("[%5lu]: request location of privileged pipe\n", (unsigned long)state->pid));
 	
-	state->response.extra_data = strdup(get_winbind_priv_pipe_dir());
+	state->response.extra_data = SMB_STRDUP(get_winbind_priv_pipe_dir());
 	if (!state->response.extra_data)
 		return WINBINDD_ERROR;
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_pam.c samba-3.0.9/source/nsswitch/winbindd_pam.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_pam.c	2004-11-15 21:03:18.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_pam.c	2004-12-09 09:00:27.168623506 -0600
@@ -43,7 +43,7 @@
 	}
 
 	size = prs_data_size(&ps);
-	state->response.extra_data = malloc(size);
+	state->response.extra_data = SMB_MALLOC(size);
 	if (!state->response.extra_data) {
 		prs_mem_free(&ps);
 		return NT_STATUS_NO_MEMORY;
@@ -78,7 +78,7 @@
 		return NT_STATUS_INVALID_PARAMETER;
 	}
 
-	all_sids = talloc(mem_ctx, sizeof(DOM_SID) * num_all_sids);
+	all_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_all_sids);
 	if (!all_sids)
 		return NT_STATUS_NO_MEMORY;
 
@@ -363,7 +363,7 @@
 	if ( NT_STATUS_IS_OK(result) &&
 	     (state->request.flags & WBFLAG_PAM_AFS_TOKEN) ) {
 
-		char *afsname = strdup(lp_afs_username_map());
+		char *afsname = SMB_STRDUP(lp_afs_username_map());
 		char *cell;
 
 		if (afsname == NULL) goto no_token;
@@ -600,7 +600,7 @@
 
 			DEBUG(5, ("Setting unix username to [%s]\n", username_out));
 
-			state->response.extra_data = strdup(username_out);
+			state->response.extra_data = SMB_STRDUP(username_out);
 			if (!state->response.extra_data) {
 				result = NT_STATUS_NO_MEMORY;
 				goto done;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_passdb.c samba-3.0.9/source/nsswitch/winbindd_passdb.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_passdb.c	2004-11-15 21:03:18.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_passdb.c	2004-12-09 09:00:27.166624003 -0600
@@ -217,8 +217,7 @@
 		return NT_STATUS_OK;
 	}
 
-	talloced_info =	(struct acct_info *)
-		talloc_memdup(mem_ctx, *info,
+	talloced_info =	(struct acct_info *)TALLOC_MEMDUP(mem_ctx, *info,
 			      *num_entries * sizeof(struct acct_info));
 
 	SAFE_FREE(*info);
@@ -332,15 +331,12 @@
 		nt_status = secrets_get_trusted_domains(mem_ctx, &enum_ctx, 1,
 							&num_sec_domains,
 							&domains);
-		*names = talloc_realloc(mem_ctx, *names,
-					sizeof(*names) *
-					(num_sec_domains + *num_domains));
-		*alt_names = talloc_realloc(mem_ctx, *alt_names,
-					    sizeof(*alt_names) *
-					    (num_sec_domains + *num_domains));
-		*dom_sids = talloc_realloc(mem_ctx, *dom_sids,
-					   sizeof(**dom_sids) *
-					   (num_sec_domains + *num_domains));
+		*names = TALLOC_REALLOC_ARRAY(mem_ctx, *names, char *,
+					num_sec_domains + *num_domains);
+		*alt_names = TALLOC_REALLOC_ARRAY(mem_ctx, *alt_names, char *,
+					    num_sec_domains + *num_domains);
+		*dom_sids = TALLOC_REALLOC_ARRAY(mem_ctx, *dom_sids, DOM_SID,
+					   num_sec_domains + *num_domains);
 
 		for (i=0; i< num_sec_domains; i++) {
 			if (pull_ucs2_talloc(mem_ctx, &(*names)[*num_domains],
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_rpc.c samba-3.0.9/source/nsswitch/winbindd_rpc.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_rpc.c	2004-11-15 21:03:17.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_rpc.c	2004-12-09 09:00:27.150627977 -0600
@@ -98,8 +98,7 @@
 
 		*num_entries += num_dom_users;
 
-		*info = talloc_realloc( mem_ctx, *info, 
-			(*num_entries) * sizeof(WINBIND_USERINFO));
+		*info = TALLOC_REALLOC_ARRAY( mem_ctx, *info, WINBIND_USERINFO, *num_entries);
 
 		if (!(*info)) {
 			result = NT_STATUS_NO_MEMORY;
@@ -192,8 +191,7 @@
 			break;
 		}
 
-		(*info) = talloc_realloc(mem_ctx, *info, 
-					 sizeof(**info) * ((*num_entries) + count));
+		(*info) = TALLOC_REALLOC_ARRAY(mem_ctx, *info, struct acct_info, (*num_entries) + count);
 		if (! *info) {
 			talloc_destroy(mem_ctx2);
 			cli_samr_close(hnd->cli, mem_ctx, &dom_pol);
@@ -255,8 +253,7 @@
 			break;
 		}
 
-		(*info) = talloc_realloc(mem_ctx, *info, 
-					 sizeof(**info) * ((*num_entries) + count));
+		(*info) = TALLOC_REALLOC_ARRAY(mem_ctx, *info, struct acct_info, (*num_entries) + count);
 		if (! *info) {
 			talloc_destroy(mem_ctx2);
 			cli_samr_close(hnd->cli, mem_ctx, &dom_pol);
@@ -491,7 +488,7 @@
 			
 		*num_groups = user->num_groups;
 				
-		(*user_grpsids) = talloc(mem_ctx, sizeof(DOM_SID*) * (*num_groups));
+		(*user_grpsids) = TALLOC_ARRAY(mem_ctx, DOM_SID*, *num_groups);
 		for (i=0;i<(*num_groups);i++) {
 			(*user_grpsids)[i] = rid_to_talloced_sid(domain, mem_ctx, user->gids[i].g_rid);
 		}
@@ -543,7 +540,7 @@
 	if (!NT_STATUS_IS_OK(result) || (*num_groups) == 0)
 		goto done;
 
-	(*user_grpsids) = talloc(mem_ctx, sizeof(DOM_SID*) * (*num_groups));
+	(*user_grpsids) = TALLOC_ARRAY(mem_ctx, DOM_SID *, *num_groups);
 	if (!(*user_grpsids)) {
 		result = NT_STATUS_NO_MEMORY;
 		goto done;
@@ -643,9 +640,9 @@
 
 #define MAX_LOOKUP_RIDS 900
 
-        *names = talloc_zero(mem_ctx, *num_names * sizeof(char *));
-        *name_types = talloc_zero(mem_ctx, *num_names * sizeof(uint32));
-        *sid_mem = talloc_zero(mem_ctx, *num_names * sizeof(DOM_SID *));
+        *names = TALLOC_ZERO_ARRAY(mem_ctx, char *, *num_names);
+        *name_types = TALLOC_ZERO_ARRAY(mem_ctx, uint32, *num_names);
+        *sid_mem = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID *, *num_names);
 
 	for (j=0;j<(*num_names);j++) {
 		(*sid_mem)[j] = rid_to_talloced_sid(domain, mem_ctx, (rid_mem)[j]);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_user.c samba-3.0.9/source/nsswitch/winbindd_user.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_user.c	2004-11-15 21:03:17.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_user.c	2004-12-09 09:00:27.146628970 -0600
@@ -351,8 +351,7 @@
 						
 		/* Create a state record for this domain */
                 
-		if ((domain_state = (struct getent_state *)
-		     malloc(sizeof(struct getent_state))) == NULL)
+		if ((domain_state = SMB_MALLOC_P(struct getent_state)) == NULL)
 			return WINBINDD_ERROR;
                 
 		ZERO_STRUCTP(domain_state);
@@ -429,10 +428,7 @@
 	if (num_entries) {
 		struct getpwent_user *tnl;
 		
-		tnl = (struct getpwent_user *)Realloc(name_list, 
-						      sizeof(struct getpwent_user) *
-						      (ent->num_sam_entries + 
-						       num_entries));
+		tnl = SMB_REALLOC_ARRAY(name_list, struct getpwent_user, ent->num_sam_entries + num_entries);
 		
 		if (!tnl) {
 			DEBUG(0,("get_sam_user_entries realloc failed.\n"));
@@ -498,8 +494,7 @@
 
 	num_users = MIN(MAX_GETPWENT_USERS, state->request.data.num_entries);
 	
-	if ((state->response.extra_data = 
-	     malloc(num_users * sizeof(struct winbindd_pw))) == NULL)
+	if ((state->response.extra_data = SMB_MALLOC_ARRAY(struct winbindd_pw, num_users)) == NULL)
 		return WINBINDD_ERROR;
 
 	memset(state->response.extra_data, 0, num_users * 
@@ -624,7 +619,7 @@
 		/* Allocate some memory for extra data */
 		total_entries += num_entries;
 			
-		ted = Realloc(extra_data, sizeof(fstring) * total_entries);
+		ted = SMB_REALLOC(extra_data, sizeof(fstring) * total_entries);
 			
 		if (!ted) {
 			DEBUG(0,("failed to enlarge buffer!\n"));
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_util.c samba-3.0.9/source/nsswitch/winbindd_util.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_util.c	2004-11-15 21:03:17.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_util.c	2004-12-09 09:00:27.143629715 -0600
@@ -139,7 +139,7 @@
         
 	/* Create new domain entry */
 
-	if ((domain = (struct winbindd_domain *)malloc(sizeof(*domain))) == NULL)
+	if ((domain = SMB_MALLOC_P(struct winbindd_domain)) == NULL)
 		return NULL;
 
 	/* Fill in fields */
@@ -777,7 +777,7 @@
 				    uint32 rid) 
 {
 	DOM_SID *sid;
-	sid = talloc(mem_ctx, sizeof(*sid));
+	sid = TALLOC_P(mem_ctx, DOM_SID);
 	if (!sid) {
 		smb_panic("rid_to_to_talloced_sid: talloc for DOM_SID failed!\n");
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/winbindd_wins.c samba-3.0.9/source/nsswitch/winbindd_wins.c
--- samba-3.0.9-orig/source/nsswitch/winbindd_wins.c	2004-11-15 21:03:17.000000000 -0600
+++ samba-3.0.9/source/nsswitch/winbindd_wins.c	2004-12-09 09:00:27.133632199 -0600
@@ -97,7 +97,7 @@
 	if (resolve_wins(name,0x20,&ret,count)) {
 		if ( count == 0 )
 			return NULL;
-		if ( (return_ip = (struct in_addr *)malloc((*count)*sizeof(struct in_addr))) == NULL ) {
+		if ( (return_ip = SMB_MALLOC_ARRAY(struct in_addr, *count)) == NULL ) {
 			free( ret );
 			return NULL;
 		}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/nsswitch/wins.c samba-3.0.9/source/nsswitch/wins.c
--- samba-3.0.9-orig/source/nsswitch/wins.c	2004-11-15 21:03:18.000000000 -0600
+++ samba-3.0.9/source/nsswitch/wins.c	2004-12-09 09:00:27.159625741 -0600
@@ -101,7 +101,7 @@
 
 	/* always try with wins first */
 	if (resolve_wins(name,0x00,&address,count)) {
-		if ( (ret = (struct in_addr *)malloc(sizeof(struct in_addr))) == NULL ) {
+		if ( (ret = SMB_MALLOC_P(struct in_addr)) == NULL ) {
 			free( address );
 			return NULL;
 		}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/param/loadparm.c samba-3.0.9/source/param/loadparm.c
--- samba-3.0.9-orig/source/param/loadparm.c	2004-11-15 21:03:16.000000000 -0600
+++ samba-3.0.9/source/param/loadparm.c	2004-12-09 09:00:27.118635925 -0600
@@ -2267,9 +2267,7 @@
 	if (i == iNumServices) {
 		service **tsp;
 		
-		tsp = (service **) Realloc(ServicePtrs,
-					   sizeof(service *) *
-					   num_to_alloc);
+		tsp = SMB_REALLOC_ARRAY(ServicePtrs, service *, num_to_alloc);
 					   
 		if (!tsp) {
 			DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
@@ -2277,8 +2275,7 @@
 		}
 		else {
 			ServicePtrs = tsp;
-			ServicePtrs[iNumServices] =
-				(service *) malloc(sizeof(service));
+			ServicePtrs[iNumServices] = SMB_MALLOC_P(service);
 		}
 		if (!ServicePtrs[iNumServices]) {
 			DEBUG(0,("add_a_service: out of memory!\n"));
@@ -2570,16 +2567,16 @@
 			if (strcmp(pdata->key, data->key) == 0) {
 				string_free(&pdata->value);
 				str_list_free(&data->list);
-				pdata->value = strdup(data->value);
+				pdata->value = SMB_STRDUP(data->value);
 				not_added = False;
 				break;
 			}
 			pdata = pdata->next;
 		}
 		if (not_added) {
-		    paramo = smb_xmalloc(sizeof(param_opt_struct));
-		    paramo->key = strdup(data->key);
-		    paramo->value = strdup(data->value);
+		    paramo = SMB_XMALLOC_P(param_opt_struct);
+		    paramo->key = SMB_STRDUP(data->key);
+		    paramo->value = SMB_STRDUP(data->value);
 		    paramo->list = NULL;
 		    DLIST_ADD(pserviceDest->param_opt, paramo);
 		}
@@ -2654,16 +2651,16 @@
 	}
 
 	if (!f) {
-		f = (struct file_lists *)malloc(sizeof(file_lists[0]));
+		f = SMB_MALLOC_P(struct file_lists);
 		if (!f)
 			return;
 		f->next = file_lists;
-		f->name = strdup(fname);
+		f->name = SMB_STRDUP(fname);
 		if (!f->name) {
 			SAFE_FREE(f);
 			return;
 		}
-		f->subfname = strdup(subfname);
+		f->subfname = SMB_STRDUP(subfname);
 		if (!f->subfname) {
 			SAFE_FREE(f);
 			return;
@@ -2713,7 +2710,7 @@
 				  ctime(&mod_time)));
 			f->modtime = mod_time;
 			SAFE_FREE(f->subfname);
-			f->subfname = strdup(n2);
+			f->subfname = SMB_STRDUP(n2);
 			return (True);
 		}
 		f = f->next;
@@ -3055,7 +3052,7 @@
 {
 	int i;
 	SAFE_FREE(pservice->copymap);
-	pservice->copymap = (BOOL *)malloc(sizeof(BOOL) * NUMPARAMETERS);
+	pservice->copymap = SMB_MALLOC_ARRAY(BOOL,NUMPARAMETERS);
 	if (!pservice->copymap)
 		DEBUG(0,
 		      ("Couldn't allocate copymap!! (size %d)\n",
@@ -3109,16 +3106,16 @@
 				if (strcmp(data->key, param_key) == 0) {
 					string_free(&data->value);
 					str_list_free(&data->list);
-					data->value = strdup(pszParmValue);
+					data->value = SMB_STRDUP(pszParmValue);
 					not_added = False;
 					break;
 				}
 				data = data->next;
 			}
 			if (not_added) {
-				paramo = smb_xmalloc(sizeof(param_opt_struct));
-				paramo->key = strdup(param_key);
-				paramo->value = strdup(pszParmValue);
+				paramo = SMB_XMALLOC_P(param_opt_struct);
+				paramo->key = SMB_STRDUP(param_key);
+				paramo->value = SMB_STRDUP(pszParmValue);
 				paramo->list = NULL;
 				if (snum < 0) {
 					DLIST_ADD(Globals.param_opt, paramo);
@@ -3661,7 +3658,7 @@
 	if (!str)
 		return;
 
-	s = strdup(str);
+	s = SMB_STRDUP(str);
 	if (!s)
 		return;
 
@@ -3760,7 +3757,7 @@
 			case P_STRING:
 			case P_USTRING:
 				if (parm_table[i].ptr) {
-					parm_table[i].def.svalue = strdup(*(char **)parm_table[i].ptr);
+					parm_table[i].def.svalue = SMB_STRDUP(*(char **)parm_table[i].ptr);
 				} else {
 					parm_table[i].def.svalue = NULL;
 				}
@@ -3768,7 +3765,7 @@
 			case P_GSTRING:
 			case P_UGSTRING:
 				if (parm_table[i].ptr) {
-					parm_table[i].def.svalue = strdup((char *)parm_table[i].ptr);
+					parm_table[i].def.svalue = SMB_STRDUP((char *)parm_table[i].ptr);
 				} else {
 					parm_table[i].def.svalue = NULL;
 				}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/param/params.c samba-3.0.9/source/param/params.c
--- samba-3.0.9-orig/source/param/params.c	2004-11-15 21:03:16.000000000 -0600
+++ samba-3.0.9/source/param/params.c	2004-12-09 09:00:27.120635428 -0600
@@ -238,7 +238,7 @@
       {
       char *tb;
       
-      tb = Realloc( bufr, bSize +BUFR_INC );
+      tb = SMB_REALLOC( bufr, bSize +BUFR_INC );
       if( NULL == tb )
         {
         DEBUG(0, ("%s Memory re-allocation failure.", func) );
@@ -335,7 +335,7 @@
       {
       char *tb;
       
-      tb = Realloc( bufr, bSize + BUFR_INC );
+      tb = SMB_REALLOC( bufr, bSize + BUFR_INC );
       if( NULL == tb )
         {
         DEBUG(0, ("%s Memory re-allocation failure.", func) );
@@ -403,7 +403,7 @@
       {
       char *tb;
       
-      tb = Realloc( bufr, bSize + BUFR_INC );
+      tb = SMB_REALLOC( bufr, bSize + BUFR_INC );
       if( NULL == tb )
         {
         DEBUG(0, ("%s Memory re-allocation failure.", func) );
@@ -521,7 +521,7 @@
   int lvl = in_client?1:0;
   myFILE *ret;
 
-  ret = (myFILE *)malloc(sizeof(*ret));
+  ret = SMB_MALLOC_P(myFILE);
   if (!ret) return NULL;
 
   ret->buf = file_load(FileName, &ret->size);
@@ -572,7 +572,7 @@
   else                                        /* If we don't have a buffer   */
     {                                         /* allocate one, then parse,   */
     bSize = BUFR_INC;                         /* then free.                  */
-    bufr = (char *)malloc( bSize );
+    bufr = (char *)SMB_MALLOC( bSize );
     if( NULL == bufr )
       {
       DEBUG(0,("%s memory allocation failure.\n", func));
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/login_cache.c samba-3.0.9/source/passdb/login_cache.c
--- samba-3.0.9-orig/source/passdb/login_cache.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/login_cache.c	2004-12-09 09:00:27.382570352 -0600
@@ -72,7 +72,7 @@
 	if (!login_cache_init())
 		return NULL;
 
-	keybuf.dptr = strdup(pdb_get_nt_username(sampass));
+	keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
 	if (!keybuf.dptr || !strlen(keybuf.dptr)) {
 		SAFE_FREE(keybuf.dptr);
 		return NULL;
@@ -84,7 +84,7 @@
 	databuf = tdb_fetch(cache, keybuf);
 	SAFE_FREE(keybuf.dptr);
 
-	if (!(entry = malloc(sizeof(LOGIN_CACHE)))) {
+	if (!(entry = SMB_MALLOC_P(LOGIN_CACHE))) {
 		DEBUG(1, ("Unable to allocate cache entry buffer!\n"));
 		SAFE_FREE(databuf.dptr);
 		return NULL;
@@ -117,7 +117,7 @@
 	if (!login_cache_init())
 		return False;
 
-	keybuf.dptr = strdup(pdb_get_nt_username(sampass));
+	keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
 	if (!keybuf.dptr || !strlen(keybuf.dptr)) {
 		SAFE_FREE(keybuf.dptr);
 		return False;
@@ -132,7 +132,7 @@
 			 entry.acct_ctrl,
 			 entry.bad_password_count,
 			 entry.bad_password_time);
-	databuf.dptr = malloc(databuf.dsize);
+	databuf.dptr = SMB_MALLOC(databuf.dsize);
 	if (!databuf.dptr) {
 		SAFE_FREE(keybuf.dptr);
 		return False;
@@ -163,7 +163,7 @@
 	if (!login_cache_init()) 
 		return False;	
 
-	keybuf.dptr = strdup(pdb_get_nt_username(sampass));
+	keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
 	if (!keybuf.dptr || !strlen(keybuf.dptr)) {
 		SAFE_FREE(keybuf.dptr);
 		return False;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/lookup_sid.c samba-3.0.9/source/passdb/lookup_sid.c
--- samba-3.0.9-orig/source/passdb/lookup_sid.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/lookup_sid.c	2004-12-09 09:00:27.361575568 -0600
@@ -201,7 +201,7 @@
 		}
 	}
 
-	pc = (struct uid_sid_cache *)malloc(sizeof(struct uid_sid_cache));
+	pc = SMB_MALLOC_P(struct uid_sid_cache);
 	if (!pc)
 		return;
 	pc->uid = uid;
@@ -275,7 +275,7 @@
 		}
 	}
 
-	pc = (struct gid_sid_cache *)malloc(sizeof(struct gid_sid_cache));
+	pc = SMB_MALLOC_P(struct gid_sid_cache);
 	if (!pc)
 		return;
 	pc->gid = gid;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/machine_sid.c samba-3.0.9/source/passdb/machine_sid.c
--- samba-3.0.9-orig/source/passdb/machine_sid.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/machine_sid.c	2004-12-09 09:00:27.355577058 -0600
@@ -83,7 +83,7 @@
 	BOOL is_dc = False;
 	DOM_SID *sam_sid;
 	
-	if(!(sam_sid=(DOM_SID *)malloc(sizeof(DOM_SID))))
+	if(!(sam_sid=SMB_MALLOC_P(DOM_SID)))
 		return NULL;
 			
 	generate_wellknown_sids();
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/passdb.c samba-3.0.9/source/passdb/passdb.c
--- samba-3.0.9-orig/source/passdb/passdb.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/passdb.c	2004-12-09 09:00:27.369573581 -0600
@@ -133,7 +133,7 @@
 		return NT_STATUS_UNSUCCESSFUL;
 	}
 
-	*user=(SAM_ACCOUNT *)talloc(mem_ctx, sizeof(SAM_ACCOUNT));
+	*user=TALLOC_P(mem_ctx, SAM_ACCOUNT);
 
 	if (*user==NULL) {
 		DEBUG(0,("pdb_init_sam_talloc: error while allocating memory\n"));
@@ -1885,7 +1885,7 @@
 	/* Change from V1 is addition of password history field. */
 	account_policy_get(AP_PASSWORD_HISTORY, &pwHistLen);
 	if (pwHistLen) {
-		char *pw_hist = malloc(pwHistLen * PW_HISTORY_ENTRY_LEN);
+		char *pw_hist = SMB_MALLOC(pwHistLen * PW_HISTORY_ENTRY_LEN);
 		if (!pw_hist) {
 			ret = False;
 			goto done;
@@ -2164,7 +2164,7 @@
 	}
 
 	/* malloc the space needed */
-	if ( (*buf=(uint8*)malloc(len)) == NULL) {
+	if ( (*buf=(uint8*)SMB_MALLOC(len)) == NULL) {
 		DEBUG(0,("init_buffer_from_sam_v2: Unable to malloc() memory for buffer!\n"));
 		return (-1);
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/pdb_get_set.c samba-3.0.9/source/passdb/pdb_get_set.c
--- samba-3.0.9-orig/source/passdb/pdb_get_set.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/pdb_get_set.c	2004-12-09 09:00:27.374572339 -0600
@@ -1224,7 +1224,7 @@
 
 				if (current_history_len < pwHistLen) {
 					/* Ensure we have space for the needed history. */
-					uchar *new_history = talloc(sampass->mem_ctx,
+					uchar *new_history = TALLOC(sampass->mem_ctx,
 								pwHistLen*PW_HISTORY_ENTRY_LEN);
 					/* And copy it into the new buffer. */
 					if (current_history_len) {
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/pdb_interface.c samba-3.0.9/source/passdb/pdb_interface.c
--- samba-3.0.9-orig/source/passdb/pdb_interface.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/pdb_interface.c	2004-12-09 09:00:27.378571346 -0600
@@ -98,7 +98,7 @@
 		return NT_STATUS_OBJECT_NAME_COLLISION;
 	}
 
-	entry = smb_xmalloc(sizeof(struct pdb_init_function_entry));
+	entry = SMB_XMALLOC_P(struct pdb_init_function_entry);
 	entry->name = smb_xstrdup(name);
 	entry->init = init;
 
@@ -692,7 +692,7 @@
 		return NT_STATUS_NO_MEMORY;
 	}		
 
-	*context = talloc(mem_ctx, sizeof(**context));
+	*context = TALLOC_P(mem_ctx, struct pdb_context);
 	if (!*context) {
 		DEBUG(0, ("make_pdb_context: talloc failed!\n"));
 		return NT_STATUS_NO_MEMORY;
@@ -1198,7 +1198,7 @@
 
 NTSTATUS make_pdb_methods(TALLOC_CTX *mem_ctx, PDB_METHODS **methods) 
 {
-	*methods = talloc(mem_ctx, sizeof(struct pdb_methods));
+	*methods = TALLOC_P(mem_ctx, struct pdb_methods);
 
 	if (!*methods) {
 		return NT_STATUS_NO_MEMORY;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/pdb_ldap.c samba-3.0.9/source/passdb/pdb_ldap.c
--- samba-3.0.9-orig/source/passdb/pdb_ldap.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/pdb_ldap.c	2004-12-09 09:00:27.359576065 -0600
@@ -730,7 +730,7 @@
 		/* We can only store (sizeof(pstring)-1)/64 password history entries. */
 		pwHistLen = MIN(pwHistLen, ((sizeof(temp)-1)/64));
 
-		if ((pwhist = malloc(pwHistLen * PW_HISTORY_ENTRY_LEN)) == NULL){
+		if ((pwhist = SMB_MALLOC(pwHistLen * PW_HISTORY_ENTRY_LEN)) == NULL){
 			DEBUG(0, ("init_sam_from_ldap: malloc failed!\n"));
 			return False;
 		}
@@ -1266,9 +1266,9 @@
 		;
 	}
 
-	(*attr_list) = Realloc((*attr_list), sizeof(**attr_list) * (i+2));
+	(*attr_list) = SMB_REALLOC_ARRAY((*attr_list), char *,  i+2);
 	SMB_ASSERT((*attr_list) != NULL);
-	(*attr_list)[i] = strdup(new_attr);
+	(*attr_list)[i] = SMB_STRDUP(new_attr);
 	(*attr_list)[i+1] = NULL;
 }
 
@@ -2535,7 +2535,7 @@
 			continue;
 		}
 
-		mapt=(GROUP_MAP *)Realloc((*rmap), (entries+1)*sizeof(GROUP_MAP));
+		mapt=SMB_REALLOC_ARRAY((*rmap), GROUP_MAP, entries+1);
 		if (!mapt) {
 			DEBUG(0,("ldapsam_enum_group_mapping: Unable to enlarge group map!\n"));
 			SAFE_FREE(*rmap);
@@ -2859,7 +2859,7 @@
 
 	/* TODO: Setup private data and free */
 
-	ldap_state = talloc_zero(pdb_context->mem_ctx, sizeof(*ldap_state));
+	ldap_state = TALLOC_ZERO_P(pdb_context->mem_ctx, struct ldapsam_privates);
 	if (!ldap_state) {
 		DEBUG(0, ("pdb_init_ldapsam_common: 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/passdb/pdb_smbpasswd.c samba-3.0.9/source/passdb/pdb_smbpasswd.c
--- samba-3.0.9-orig/source/passdb/pdb_smbpasswd.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/pdb_smbpasswd.c	2004-12-09 09:00:27.380570849 -0600
@@ -551,7 +551,7 @@
 	new_entry_length = strlen(newpwd->smb_name) + 1 + 15 + 1 + 32 + 1 + 32 + 1 + 
 				NEW_PW_FORMAT_SPACE_PADDED_LEN + 1 + 13 + 2;
 
-	if((new_entry = (char *)malloc( new_entry_length )) == NULL) {
+	if((new_entry = (char *)SMB_MALLOC( new_entry_length )) == NULL) {
 		DEBUG(0, ("format_new_smbpasswd_entry: Malloc failed adding entry for user %s.\n",
 			newpwd->smb_name ));
 		return NULL;
@@ -1505,7 +1505,7 @@
 
 	/* Setup private data and free function */
 
-	privates = talloc_zero(pdb_context->mem_ctx, sizeof(struct smbpasswd_privates));
+	privates = TALLOC_ZERO_P(pdb_context->mem_ctx, struct smbpasswd_privates);
 
 	if (!privates) {
 		DEBUG(0, ("talloc() failed for smbpasswd private_data!\n"));
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/pdb_sql.c samba-3.0.9/source/passdb/pdb_sql.c
--- samba-3.0.9-orig/source/passdb/pdb_sql.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/pdb_sql.c	2004-12-09 09:00:27.375572091 -0600
@@ -78,7 +78,7 @@
 
 char *sql_escape_string(const char *unesc)
 {
-	char *esc = malloc(strlen(unesc) * 2 + 3);
+	char *esc = SMB_MALLOC(strlen(unesc) * 2 + 3);
 	size_t pos_unesc = 0, pos_esc = 0;
 
 	for(pos_unesc = 0; unesc[pos_unesc]; pos_unesc++) {
@@ -472,7 +472,7 @@
 								   " VALUES (%s", query.part2);
 	}
 
-	ret = strdup(query.part1);
+	ret = SMB_STRDUP(query.part1);
 	talloc_destroy(query.mem_ctx);
 	return ret;
 }
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/pdb_tdb.c samba-3.0.9/source/passdb/pdb_tdb.c
--- samba-3.0.9-orig/source/passdb/pdb_tdb.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/pdb_tdb.c	2004-12-09 09:00:27.353577555 -0600
@@ -267,7 +267,7 @@
 	struct pwent_list *ptr;
 	
 	if ( strncmp(key.dptr, prefix, prefixlen) == 0 ) {
-		if ( !(ptr=(struct pwent_list*)malloc(sizeof(struct pwent_list))) ) {
+		if ( !(ptr=SMB_MALLOC_P(struct pwent_list)) ) {
 			DEBUG(0,("tdbsam_traverse_setpwent: Failed to malloc new entry for list\n"));
 			
 			/* just return 0 and let the traversal continue */
@@ -724,7 +724,7 @@
 	(*pdb_method)->update_sam_account = tdbsam_update_sam_account;
 	(*pdb_method)->delete_sam_account = tdbsam_delete_sam_account;
 
-	tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates));
+	tdb_state = TALLOC_ZERO_P(pdb_context->mem_ctx, struct tdbsam_privates);
 
 	if (!tdb_state) {
 		DEBUG(0, ("talloc() failed for tdbsam private_data!\n"));
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/privileges.c samba-3.0.9/source/passdb/privileges.c
--- samba-3.0.9-orig/source/passdb/privileges.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/privileges.c	2004-12-09 09:00:27.365574575 -0600
@@ -121,7 +121,7 @@
 	*count = i;
 
 	/* allocate and parse */
-	*sids = malloc(sizeof(DOM_SID) * *count);
+	*sids = SMB_MALLOC_ARRAY(DOM_SID, *count);
 	if (! *sids) {
 		return NT_STATUS_NO_MEMORY;
 	}
@@ -154,7 +154,7 @@
 	}
 
 	/* allocate the maximum size that we might use */
-	data.dptr = malloc(count * ((MAXSUBAUTHS*11) + 30));
+	data.dptr = SMB_MALLOC(count * ((MAXSUBAUTHS*11) + 30));
 	if (!data.dptr) {
 		return NT_STATUS_NO_MEMORY;
 	}
@@ -210,7 +210,7 @@
 	}
 
 	/* add it in */
-	current_sids = Realloc(current_sids, sizeof(current_sids[0]) * (current_count+1));
+	current_sids = SMB_REALLOC_ARRAY(current_sids, DOM_SID, current_count+1);
 	if (!current_sids) {
 		privilege_unlock_right(right);
 		return NT_STATUS_NO_MEMORY;
@@ -323,14 +323,14 @@
 		right = key.dptr;
 		
 		if (privilege_sid_has_right(sid, right)) {
-			(*rights) = (char **)Realloc(*rights,sizeof(char *) * ((*count)+1));
+			(*rights) = SMB_REALLOC_ARRAY(*rights,char *, (*count)+1);
 			if (! *rights) {
 				safe_free(nextkey.dptr);
 				free(key.dptr);
 				return NT_STATUS_NO_MEMORY;
 			}
 
-			(*rights)[*count] = strdup(right);
+			(*rights)[*count] = SMB_STRDUP(right);
 			(*count)++;
 		}
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/secrets.c samba-3.0.9/source/passdb/secrets.c
--- samba-3.0.9-orig/source/passdb/secrets.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/secrets.c	2004-12-09 09:00:27.364574823 -0600
@@ -346,7 +346,7 @@
 			
 	/* the trust's password */	
 	if (pwd) {
-		*pwd = strdup(pass.pass);
+		*pwd = SMB_STRDUP(pass.pass);
 		if (!*pwd) {
 			return False;
 		}
@@ -577,7 +577,7 @@
 	size_t size, packed_size = 0;
 	fstring dom_name;
 	char *packed_pass;
-	struct trusted_dom_pass *pass = talloc_zero(ctx, sizeof(struct trusted_dom_pass));
+	struct trusted_dom_pass *pass = TALLOC_ZERO_P(ctx, struct trusted_dom_pass);
 	NTSTATUS status;
 
 	if (!secrets_init()) return NT_STATUS_ACCESS_DENIED;
@@ -599,7 +599,7 @@
 	DEBUG(5, ("secrets_get_trusted_domains: looking for %d domains, starting at index %d\n", 
 		  max_num_domains, *enum_ctx));
 
-	*domains = talloc_zero(ctx, sizeof(**domains)*max_num_domains);
+	*domains = TALLOC_ZERO_ARRAY(ctx, TRUSTDOM *, max_num_domains);
 
 	/* fetching trusted domains' data and collecting them in a list */
 	keys = tdb_search_keys(tdb, pattern);
@@ -615,7 +615,7 @@
 		char *secrets_key;
 		
 		/* important: ensure null-termination of the key string */
-		secrets_key = strndup(k->node_key.dptr, k->node_key.dsize);
+		secrets_key = SMB_STRNDUP(k->node_key.dptr, k->node_key.dsize);
 		if (!secrets_key) {
 			DEBUG(0, ("strndup failed!\n"));
 			return NT_STATUS_NO_MEMORY;
@@ -638,7 +638,7 @@
 		SAFE_FREE(secrets_key);
 
 		if (idx >= start_idx && idx < start_idx + max_num_domains) {
-			dom = talloc_zero(ctx, sizeof(*dom));
+			dom = TALLOC_ZERO_P(ctx, TRUSTDOM);
 			if (!dom) {
 				/* free returned tdb record */
 				return NT_STATUS_NO_MEMORY;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/passdb/util_sam_sid.c samba-3.0.9/source/passdb/util_sam_sid.c
--- samba-3.0.9-orig/source/passdb/util_sam_sid.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/passdb/util_sam_sid.c	2004-12-09 09:00:27.371573084 -0600
@@ -106,16 +106,16 @@
 		/* This is not lp_workgroup() for good reason:
 		   it must stay around longer than the lp_*() 
 		   strings do */
-		sid_name_map[i].name = strdup(lp_workgroup());
+		sid_name_map[i].name = SMB_STRDUP(lp_workgroup());
 		sid_name_map[i].known_users = NULL;
 		i++;
 		sid_name_map[i].sid = get_global_sam_sid();
-		sid_name_map[i].name = strdup(global_myname());
+		sid_name_map[i].name = SMB_STRDUP(global_myname());
 		sid_name_map[i].known_users = NULL;
 		i++;
 	} else {
 		sid_name_map[i].sid = get_global_sam_sid();
-		sid_name_map[i].name = strdup(global_myname());
+		sid_name_map[i].name = SMB_STRDUP(global_myname());
 		sid_name_map[i].known_users = NULL;
 		i++;
 	}
@@ -317,7 +317,7 @@
 
 void add_sid_to_array(const DOM_SID *sid, DOM_SID **sids, int *num)
 {
-	*sids = Realloc(*sids, ((*num)+1) * sizeof(DOM_SID));
+	*sids = SMB_REALLOC_ARRAY(*sids, DOM_SID, (*num)+1);
 
 	if (*sids == NULL)
 		return;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/printing/load.c samba-3.0.9/source/printing/load.c
--- samba-3.0.9-orig/source/printing/load.c	2004-11-15 21:03:15.000000000 -0600
+++ samba-3.0.9/source/printing/load.c	2004-12-09 09:00:27.091642631 -0600
@@ -40,7 +40,7 @@
 {
 	const char *p;
 	int printers;
-	char *str = strdup(lp_auto_services());
+	char *str = SMB_STRDUP(lp_auto_services());
 
 	if (!str) return;
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/printing/notify.c samba-3.0.9/source/printing/notify.c
--- samba-3.0.9-orig/source/printing/notify.c	2004-11-15 21:03:15.000000000 -0600
+++ samba-3.0.9/source/printing/notify.c	2004-12-09 09:00:27.096641389 -0600
@@ -99,7 +99,7 @@
 				msg->len, msg->notify.data);
 
 	if (buflen != len) {
-		buf = talloc_realloc(send_ctx, buf, len);
+		buf = TALLOC_REALLOC(send_ctx, buf, len);
 		if (!buf)
 			return False;
 		buflen = len;
@@ -140,7 +140,7 @@
 	}
 	offset += 4; /* For count. */
 
-	buf = talloc(send_ctx, offset);
+	buf = TALLOC(send_ctx, offset);
 	if (!buf) {
 		DEBUG(0,("print_notify_send_messages: Out of memory\n"));
 		talloc_destroy_pool(send_ctx);
@@ -218,7 +218,7 @@
 	memcpy( to, from, sizeof(SPOOLSS_NOTIFY_MSG) );
 	
 	if ( from->len ) {
-		to->notify.data = talloc_memdup(send_ctx, from->notify.data, from->len );
+		to->notify.data = TALLOC_MEMDUP(send_ctx, from->notify.data, from->len );
 		if ( !to->notify.data ) {
 			DEBUG(0,("copy_notify2_msg: talloc_memdup() of size [%d] failed!\n", from->len ));
 			return False;
@@ -267,7 +267,7 @@
 
 	/* Store the message on the pending queue. */
 
-	pnqueue = talloc(send_ctx, sizeof(*pnqueue));
+	pnqueue = TALLOC_P(send_ctx, struct notify_queue);
 	if (!pnqueue) {
 		DEBUG(0,("send_spoolss_notify2_msg: Out of memory.\n"));
 		return;
@@ -275,7 +275,7 @@
 
 	/* allocate a new msg structure and copy the fields */
 	
-	if ( !(pnqueue->msg = (SPOOLSS_NOTIFY_MSG*)talloc(send_ctx, sizeof(SPOOLSS_NOTIFY_MSG))) ) {
+	if ( !(pnqueue->msg = TALLOC_P(send_ctx, SPOOLSS_NOTIFY_MSG)) ) {
 		DEBUG(0,("send_spoolss_notify2_msg: talloc() of size [%lu] failed!\n", 
 			(unsigned long)sizeof(SPOOLSS_NOTIFY_MSG)));
 		return;
@@ -309,7 +309,7 @@
 	if (!create_send_ctx())
 		return;
 
-	msg = (struct spoolss_notify_msg *)talloc(send_ctx, sizeof(struct spoolss_notify_msg));
+	msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
 	if (!msg)
 		return;
 
@@ -338,7 +338,7 @@
 	if (!create_send_ctx())
 		return;
 
-	msg = (struct spoolss_notify_msg *)talloc(send_ctx, sizeof(struct spoolss_notify_msg));
+	msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
 	if (!msg)
 		return;
 
@@ -535,7 +535,7 @@
 
 	num_pids = data.dsize / 8;
 
-	if ((pid_list = (pid_t *)talloc(mem_ctx, sizeof(pid_t) * num_pids)) == NULL) {
+	if ((pid_list = TALLOC_ARRAY(mem_ctx, pid_t, num_pids)) == NULL) {
 		ret = False;
 		goto done;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/printing/nt_printing.c samba-3.0.9/source/printing/nt_printing.c
--- samba-3.0.9-orig/source/printing/nt_printing.c	2004-11-15 21:03:15.000000000 -0600
+++ samba-3.0.9/source/printing/nt_printing.c	2004-12-09 09:00:27.108638409 -0600
@@ -531,7 +531,7 @@
 		if (ret != dbuf.dsize) 
 			continue;
 
-		tl = Realloc(*list, sizeof(nt_forms_struct)*(n+1));
+		tl = SMB_REALLOC_ARRAY(*list, nt_forms_struct, n+1);
 		if (!tl) {
 			DEBUG(0,("get_ntforms: Realloc fail.\n"));
 			return 0;
@@ -601,7 +601,7 @@
 	}
 
 	if (update==False) {
-		if((tl=Realloc(*list, (n+1)*sizeof(nt_forms_struct))) == NULL) {
+		if((tl=SMB_REALLOC_ARRAY(*list, nt_forms_struct, n+1)) == NULL) {
 			DEBUG(0,("add_a_form: failed to enlarge forms list!\n"));
 			return False;
 		}
@@ -710,7 +710,7 @@
 		if (strncmp(kbuf.dptr, key, strlen(key)) != 0)
 			continue;
 		
-		if((fl = Realloc(*list, sizeof(fstring)*(total+1))) == NULL) {
+		if((fl = SMB_REALLOC_ARRAY(*list, fstring, total+1)) == NULL) {
 			DEBUG(0,("get_ntdrivers: failed to enlarge list!\n"));
 			return -1;
 		}
@@ -766,7 +766,7 @@
 	char    *buf = NULL;
 	ssize_t byte_count;
 
-	if ((buf=malloc(PE_HEADER_SIZE)) == NULL) {
+	if ((buf=SMB_MALLOC(PE_HEADER_SIZE)) == NULL) {
 		DEBUG(0,("get_file_version: PE file [%s] PE Header malloc failed bytes = %d\n",
 				fname, PE_HEADER_SIZE));
 		goto error_exit;
@@ -822,7 +822,7 @@
 			goto error_exit;
 
 		SAFE_FREE(buf);
-		if ((buf=malloc(section_table_bytes)) == NULL) {
+		if ((buf=SMB_MALLOC(section_table_bytes)) == NULL) {
 			DEBUG(0,("get_file_version: PE file [%s] section table malloc failed bytes = %d\n",
 					fname, section_table_bytes));
 			goto error_exit;
@@ -846,7 +846,7 @@
 					goto error_exit;
 
 				SAFE_FREE(buf);
-				if ((buf=malloc(section_bytes)) == NULL) {
+				if ((buf=SMB_MALLOC(section_bytes)) == NULL) {
 					DEBUG(0,("get_file_version: PE file [%s] version malloc failed bytes = %d\n",
 							fname, section_bytes));
 					goto error_exit;
@@ -906,7 +906,7 @@
 
 		/* Allocate a bit more space to speed up things */
 		SAFE_FREE(buf);
-		if ((buf=malloc(VS_NE_BUF_SIZE)) == NULL) {
+		if ((buf=SMB_MALLOC(VS_NE_BUF_SIZE)) == NULL) {
 			DEBUG(0,("get_file_version: NE file [%s] malloc failed bytes  = %d\n",
 					fname, PE_HEADER_SIZE));
 			goto error_exit;
@@ -1728,7 +1728,7 @@
 	if (len != buflen) {
 		char *tb;
 
-		tb = (char *)Realloc(buf, len);
+		tb = (char *)SMB_REALLOC(buf, len);
 		if (!tb) {
 			DEBUG(0,("add_a_printer_driver_3: failed to enlarge buffer\n!"));
 			ret = -1;
@@ -1793,7 +1793,7 @@
 	fstrcpy(info.configfile, "");
 	fstrcpy(info.helpfile, "");
 
-	if ((info.dependentfiles=(fstring *)malloc(2*sizeof(fstring))) == NULL)
+	if ((info.dependentfiles= SMB_MALLOC_ARRAY(fstring, 2)) == NULL)
 		return WERR_NOMEM;
 
 	memset(info.dependentfiles, '\0', 2*sizeof(fstring));
@@ -1850,8 +1850,7 @@
 	while (len < dbuf.dsize) {
 		fstring *tddfs;
 
-		tddfs = (fstring *)Realloc(driver.dependentfiles,
-							 sizeof(fstring)*(i+2));
+		tddfs = SMB_REALLOC_ARRAY(driver.dependentfiles, fstring, i+2);
 		if (tddfs == NULL) {
 			DEBUG(0,("get_a_printer_driver_3: failed to enlarge buffer!\n"));
 			break;
@@ -2133,7 +2132,7 @@
 	if (buflen != len) {
 		char *tb;
 
-		tb = (char *)Realloc(buf, len);
+		tb = (char *)SMB_REALLOC(buf, len);
 		if (!tb) {
 			DEBUG(0,("update_a_printer_2: failed to enlarge buffer!\n"));
 			ret = WERR_NOMEM;
@@ -2175,7 +2174,7 @@
 {
 
 	char adevice[MAXDEVICENAME];
-	NT_DEVICEMODE *nt_devmode = (NT_DEVICEMODE *)malloc(sizeof(NT_DEVICEMODE));
+	NT_DEVICEMODE *nt_devmode = SMB_MALLOC_P(NT_DEVICEMODE);
 
 	if (nt_devmode == NULL) {
 		DEBUG(0,("construct_nt_devicemode: malloc fail.\n"));
@@ -2395,7 +2394,7 @@
 	
 	/* allocate another slot in the NT_PRINTER_KEY array */
 	
-	d = Realloc( data->keys, sizeof(NT_PRINTER_KEY)*(data->num_keys+1) );
+	d = SMB_REALLOC_ARRAY( data->keys, NT_PRINTER_KEY, data->num_keys+1);
 	if ( d )
 		data->keys = d;
 	
@@ -2404,7 +2403,7 @@
 	/* initialze new key */
 	
 	data->num_keys++;
-	data->keys[key_index].name = strdup( name );
+	data->keys[key_index].name = SMB_STRDUP( name );
 	
 	ZERO_STRUCTP( &data->keys[key_index].values );
 	
@@ -2487,7 +2486,7 @@
 
 			/* found a match, so allocate space and copy the name */
 			
-			if ( !(ptr = Realloc( subkeys_ptr, (num_subkeys+2)*sizeof(fstring))) ) {
+			if ( !(ptr = SMB_REALLOC_ARRAY( subkeys_ptr, fstring, num_subkeys+2)) ) {
 				DEBUG(0,("get_printer_subkeys: Realloc failed for [%d] entries!\n", 
 					num_subkeys+1));
 				SAFE_FREE( subkeys );
@@ -2550,9 +2549,14 @@
 
 	/* a multi-sz has to have a null string terminator, i.e., the last
 	   string must be followed by two nulls */
-	str_size = (strlen(multi_sz) + 2) * sizeof(smb_ucs2_t);
-	conv_strs = calloc(str_size, 1);
+	str_size = strlen(multi_sz) + 2;
+	conv_strs = SMB_CALLOC_ARRAY(smb_ucs2_t, str_size);
+	if (!conv_strs) {
+		return;
+	}
 
+	/* Change to byte units. */
+	str_size *= sizeof(smb_ucs2_t);
 	push_ucs2(NULL, conv_strs, multi_sz, str_size, 
 		  STR_TERMINATE | STR_NOALIGN);
 
@@ -3787,7 +3791,7 @@
 	if (buflen < len) {
 		char *tb;
 
-		tb = (char *)Realloc(buf, len);
+		tb = (char *)SMB_REALLOC(buf, len);
 		if (!tb) {
 			DEBUG(0, ("update_driver_init_2: failed to enlarge buffer!\n"));
 			ret = -1;
@@ -3911,7 +3915,7 @@
 		if ((ctx = talloc_init("save_driver_init_2")) == NULL)
 			return WERR_NOMEM;
 
-		if ((nt_devmode = (NT_DEVICEMODE*)malloc(sizeof(NT_DEVICEMODE))) == NULL) {
+		if ((nt_devmode = SMB_MALLOC_P(NT_DEVICEMODE)) == NULL) {
 			status = WERR_NOMEM;
 			goto done;
 		}
@@ -4028,7 +4032,7 @@
 	if ( !printer )
 		return NULL;
 	
-	if ( !(copy = (NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2))) )
+	if ( !(copy = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL_2)) )
 		return NULL;
 		
 	memcpy( copy, printer, sizeof(NT_PRINTER_INFO_LEVEL_2) );
@@ -4076,7 +4080,7 @@
 
 	switch (level) {
 		case 2:
-			if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) {
+			if ((printer = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL)) == NULL) {
 				DEBUG(0,("get_a_printer: malloc fail.\n"));
 				return WERR_NOMEM;
 			}
@@ -4137,7 +4141,7 @@
 				/* save a copy in cache */
 				if ( print_hnd && (print_hnd->printer_type==PRINTER_HANDLE_IS_PRINTER)) {
 					if ( !print_hnd->printer_info )
-						print_hnd->printer_info = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL));
+						print_hnd->printer_info = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL);
 
 					if ( print_hnd->printer_info ) {
 						/* make sure to use the handle's talloc ctx here since 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/printing/print_cups.c samba-3.0.9/source/printing/print_cups.c
--- samba-3.0.9-orig/source/printing/print_cups.c	2004-11-15 21:03:15.000000000 -0600
+++ samba-3.0.9/source/printing/print_cups.c	2004-12-09 09:00:27.093642134 -0600
@@ -931,7 +931,7 @@
 		{
 			qalloc += 16;
 
-			temp = Realloc(queue, sizeof(print_queue_struct) * qalloc);
+			temp = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
 
 			if (temp == NULL)
 			{
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/printing/print_generic.c samba-3.0.9/source/printing/print_generic.c
--- samba-3.0.9-orig/source/printing/print_generic.c	2004-11-15 21:03:15.000000000 -0600
+++ samba-3.0.9/source/printing/print_generic.c	2004-12-09 09:00:27.094641886 -0600
@@ -194,7 +194,7 @@
 	qcount = 0;
 	ZERO_STRUCTP(status);
 	if (numlines)
-		queue = (print_queue_struct *)malloc(sizeof(print_queue_struct)*(numlines+1));
+		queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
 
 	if (queue) {
 		memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/printing/printing.c samba-3.0.9/source/printing/printing.c
--- samba-3.0.9-orig/source/printing/printing.c	2004-11-15 21:03:15.000000000 -0600
+++ samba-3.0.9/source/printing/printing.c	2004-12-09 09:00:27.100640396 -0600
@@ -529,7 +529,7 @@
 		if (buflen != len) {
 			char *tb;
 
-			tb = (char *)Realloc(buf, len);
+			tb = (char *)SMB_REALLOC(buf, len);
 			if (!tb) {
 				DEBUG(0,("pjob_store: failed to enlarge buffer!\n"));
 				goto done;
@@ -923,7 +923,7 @@
 				queue[i].fs_file);
 	}
 
-	if ((data.dptr = malloc(data.dsize)) == NULL)
+	if ((data.dptr = SMB_MALLOC(data.dsize)) == NULL)
 		return;
 
         len = 0;
@@ -1362,7 +1362,7 @@
 
 	if (i == data.dsize) {
 		/* We weren't in the list. Realloc. */
-		data.dptr = Realloc(data.dptr, data.dsize + 8);
+		data.dptr = SMB_REALLOC(data.dptr, data.dsize + 8);
 		if (!data.dptr) {
 			DEBUG(0,("print_notify_register_pid: Relloc fail for printer %s\n",
 						printername));
@@ -2357,7 +2357,7 @@
 	if (qcount == 0 && extra_count == 0)
 		goto out;
 
-	if ((queue = (print_queue_struct *)malloc(sizeof(print_queue_struct)*(qcount + extra_count))) == NULL)
+	if ((queue = SMB_MALLOC_ARRAY(print_queue_struct, qcount + extra_count)) == NULL)
 		goto out;
 
 	/* Retrieve the linearised queue data. */
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/printing/printing_db.c samba-3.0.9/source/printing/printing_db.c
--- samba-3.0.9-orig/source/printing/printing_db.c	2004-11-15 21:03:15.000000000 -0600
+++ samba-3.0.9/source/printing/printing_db.c	2004-12-09 09:00:27.090642880 -0600
@@ -80,7 +80,7 @@
        
 	if (!p)	{
 		/* Create one. */
-		p = (struct tdb_print_db *)malloc(sizeof(struct tdb_print_db));
+		p = SMB_MALLOC_P(struct tdb_print_db);
 		if (!p) {
 			DEBUG(0,("get_print_db: malloc fail !\n"));
 			return NULL;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/registry/reg_cachehook.c samba-3.0.9/source/registry/reg_cachehook.c
--- samba-3.0.9-orig/source/registry/reg_cachehook.c	2004-11-15 21:03:34.000000000 -0600
+++ samba-3.0.9/source/registry/reg_cachehook.c	2004-12-09 09:00:27.585519931 -0600
@@ -78,7 +78,7 @@
 	/* prepend the string with a '\' character */
 	
 	len = strlen( keyname );
-	if ( !(key = malloc( len + 2 )) ) {
+	if ( !(key = SMB_MALLOC( len + 2 )) ) {
 		DEBUG(0,("reghook_cache_find: malloc failed for string [%s] !?!?!\n",
 			keyname));
 		return NULL;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/registry/reg_db.c samba-3.0.9/source/registry/reg_db.c
--- samba-3.0.9-orig/source/registry/reg_db.c	2004-11-15 21:03:34.000000000 -0600
+++ samba-3.0.9/source/registry/reg_db.c	2004-12-09 09:00:27.587519434 -0600
@@ -183,7 +183,7 @@
 	
 	/* allocate some initial memory */
 		
-	buffer = malloc(sizeof(pstring));
+	buffer = SMB_MALLOC(sizeof(pstring));
 	buflen = sizeof(pstring);
 	len = 0;
 	
@@ -197,7 +197,7 @@
 		len += tdb_pack( buffer+len, buflen-len, "f", regsubkey_ctr_specific_key(ctr, i) );
 		if ( len > buflen ) {
 			/* allocate some extra space */
-			if ((tmpbuf = Realloc( buffer, len*2 )) == NULL) {
+			if ((tmpbuf = SMB_REALLOC( buffer, len*2 )) == NULL) {
 				DEBUG(0,("regdb_store_reg_keys: Failed to realloc memory of size [%d]\n", len*2));
 				ret = False;
 				goto done;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/registry/reg_frontend.c samba-3.0.9/source/registry/reg_frontend.c
--- samba-3.0.9-orig/source/registry/reg_frontend.c	2004-11-15 21:03:34.000000000 -0600
+++ samba-3.0.9/source/registry/reg_frontend.c	2004-12-09 09:00:27.592518192 -0600
@@ -154,7 +154,7 @@
 	if ( !(s = regsubkey_ctr_specific_key( &ctr, key_index )) )
 		return False;
 
-	*subkey = strdup( s );
+	*subkey = SMB_STRDUP( s );
 
 	return True;
 }
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/registry/reg_objects.c samba-3.0.9/source/registry/reg_objects.c
--- samba-3.0.9-orig/source/registry/reg_objects.c	2004-11-15 21:03:34.000000000 -0600
+++ samba-3.0.9/source/registry/reg_objects.c	2004-12-09 09:00:27.588519185 -0600
@@ -52,16 +52,16 @@
 		/* allocate a space for the char* in the array */
 		
 		if (  ctr->subkeys == 0 )
-			ctr->subkeys = talloc( ctr->ctx, sizeof(char*) );
+			ctr->subkeys = TALLOC_P( ctr->ctx, char *);
 		else {
-			pp = talloc_realloc( ctr->ctx, ctr->subkeys, sizeof(char*)*(ctr->num_subkeys+1) );
+			pp = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->subkeys, char *, ctr->num_subkeys+1);
 			if ( pp )
 				ctr->subkeys = pp;
 		}
 
 		/* allocate the string and save it in the array */
 		
-		ctr->subkeys[ctr->num_subkeys] = talloc( ctr->ctx, len+1 );
+		ctr->subkeys[ctr->num_subkeys] = TALLOC( ctr->ctx, len+1 );
 		strncpy( ctr->subkeys[ctr->num_subkeys], keyname, len+1 );
 		ctr->num_subkeys++;
 	}
@@ -138,7 +138,7 @@
 	if ( !val )
 		return NULL;
 	
-	if ( !(copy = malloc( sizeof(REGISTRY_VALUE) )) ) {
+	if ( !(copy = SMB_MALLOC_P( REGISTRY_VALUE)) ) {
 		DEBUG(0,("dup_registry_value: malloc() failed!\n"));
 		return NULL;
 	}
@@ -244,22 +244,22 @@
 		/* allocate a slot in the array of pointers */
 		
 		if (  ctr->num_values == 0 )
-			ctr->values = talloc( ctr->ctx, sizeof(REGISTRY_VALUE*) );
+			ctr->values = TALLOC_P( ctr->ctx, REGISTRY_VALUE *);
 		else {
-			ppreg = talloc_realloc( ctr->ctx, ctr->values, sizeof(REGISTRY_VALUE*)*(ctr->num_values+1) );
+			ppreg = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->values, REGISTRY_VALUE *, ctr->num_values+1 );
 			if ( ppreg )
 				ctr->values = ppreg;
 		}
 
 		/* allocate a new value and store the pointer in the arrya */
 		
-		ctr->values[ctr->num_values] = talloc( ctr->ctx, sizeof(REGISTRY_VALUE) );
+		ctr->values[ctr->num_values] = TALLOC_P( ctr->ctx, REGISTRY_VALUE);
 
 		/* init the value */
 	
 		fstrcpy( ctr->values[ctr->num_values]->valuename, name );
 		ctr->values[ctr->num_values]->type = type;
-		ctr->values[ctr->num_values]->data_p = talloc_memdup( ctr->ctx, data_p, size );
+		ctr->values[ctr->num_values]->data_p = TALLOC_MEMDUP( ctr->ctx, data_p, size );
 		ctr->values[ctr->num_values]->size = size;
 		ctr->num_values++;
 	}
@@ -280,22 +280,22 @@
 		/* allocate a slot in the array of pointers */
 		
 		if (  ctr->num_values == 0 )
-			ctr->values = talloc( ctr->ctx, sizeof(REGISTRY_VALUE*) );
+			ctr->values = TALLOC_P( ctr->ctx, REGISTRY_VALUE *);
 		else {
-			ppreg = talloc_realloc( ctr->ctx, ctr->values, sizeof(REGISTRY_VALUE*)*(ctr->num_values+1) );
+			ppreg = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->values, REGISTRY_VALUE *, ctr->num_values+1 );
 			if ( ppreg )
 				ctr->values = ppreg;
 		}
 
 		/* allocate a new value and store the pointer in the arrya */
 		
-		ctr->values[ctr->num_values] = talloc( ctr->ctx, sizeof(REGISTRY_VALUE) );
+		ctr->values[ctr->num_values] = TALLOC_P( ctr->ctx, REGISTRY_VALUE);
 
 		/* init the value */
 	
 		fstrcpy( ctr->values[ctr->num_values]->valuename, val->valuename );
 		ctr->values[ctr->num_values]->type = val->type;
-		ctr->values[ctr->num_values]->data_p = talloc_memdup( ctr->ctx, val->data_p, val->size );
+		ctr->values[ctr->num_values]->data_p = TALLOC_MEMDUP( ctr->ctx, val->data_p, val->size );
 		ctr->values[ctr->num_values]->size = val->size;
 		ctr->num_values++;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/registry/reg_printing.c samba-3.0.9/source/registry/reg_printing.c
--- samba-3.0.9-orig/source/registry/reg_printing.c	2004-11-15 21:03:34.000000000 -0600
+++ samba-3.0.9/source/registry/reg_printing.c	2004-12-09 09:00:27.590518689 -0600
@@ -73,7 +73,7 @@
 		p++;
 	
 	if ( *p )
-		return strdup(p);
+		return SMB_STRDUP(p);
 	else
 		return NULL;
 }
@@ -136,7 +136,7 @@
 	
 	/* we are dealing with a subkey of "Environments */
 	
-	key2 = strdup( key );
+	key2 = SMB_STRDUP( key );
 	keystr = key2;
 	reg_split_path( keystr, &base, &new_path );
 	
@@ -257,7 +257,7 @@
 	
 	/* env */
 	
-	key2 = strdup( key );
+	key2 = SMB_STRDUP( key );
 	keystr = key2;
 	reg_split_path( keystr, &base, &new_path );
 	if ( !base || !new_path )
@@ -322,7 +322,7 @@
 			
 			length = strlen(filename);
 		
-			buffer2 = Realloc( buffer, buffer_size + (length + 1)*sizeof(uint16) );
+			buffer2 = SMB_REALLOC( buffer, buffer_size + (length + 1)*sizeof(uint16) );
 			if ( !buffer2 )
 				break;
 			buffer = buffer2;
@@ -335,7 +335,7 @@
 		
 		/* terminated by double NULL.  Add the final one here */
 		
-		buffer2 = Realloc( buffer, buffer_size + 2 );
+		buffer2 = SMB_REALLOC( buffer, buffer_size + 2 );
 		if ( !buffer2 ) {
 			SAFE_FREE( buffer );
 			buffer_size = 0;
@@ -492,7 +492,7 @@
 
 	/* get information for a specific printer */
 	
-	key2 = strdup( key );
+	key2 = SMB_STRDUP( key );
 	keystr = key2;
 	reg_split_path( keystr, &base, &new_path );
 
@@ -546,7 +546,7 @@
 		goto done;
 	}
 	
-	key2 = strdup( key );
+	key2 = SMB_STRDUP( key );
 	keystr = key2;
 	reg_split_path( keystr, &base, &new_path );
 	
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpcclient/cmd_echo.c samba-3.0.9/source/rpcclient/cmd_echo.c
--- samba-3.0.9-orig/source/rpcclient/cmd_echo.c	2004-11-15 21:03:12.000000000 -0600
+++ samba-3.0.9/source/rpcclient/cmd_echo.c	2004-12-09 09:00:26.997665979 -0600
@@ -60,7 +60,7 @@
 	}
 
 	size = atoi(argv[1]);
-	in_data = malloc(size);
+	in_data = SMB_MALLOC(size);
 
 	for (i = 0; i < size; i++)
 		in_data[i] = i & 0xff;
@@ -129,7 +129,7 @@
 	}
 
 	size = atoi(argv[1]);
-	in_data = malloc(size);
+	in_data = SMB_MALLOC(size);
 
 	for (i = 0; i < size; i++)
 		in_data[i] = i & 0xff;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpcclient/cmd_lsarpc.c samba-3.0.9/source/rpcclient/cmd_lsarpc.c
--- samba-3.0.9-orig/source/rpcclient/cmd_lsarpc.c	2004-11-15 21:03:12.000000000 -0600
+++ samba-3.0.9/source/rpcclient/cmd_lsarpc.c	2004-12-09 09:00:27.008663247 -0600
@@ -207,7 +207,7 @@
 
 	/* Convert arguments to sids */
 
-	sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * (argc - 1));
+	sids = TALLOC_ARRAY(mem_ctx, DOM_SID, argc - 1);
 
 	if (!sids) {
 		printf("could not allocate memory for %d sids\n", argc - 1);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpcclient/cmd_samr.c samba-3.0.9/source/rpcclient/cmd_samr.c
--- samba-3.0.9-orig/source/rpcclient/cmd_samr.c	2004-11-15 21:03:12.000000000 -0600
+++ samba-3.0.9/source/rpcclient/cmd_samr.c	2004-12-09 09:00:27.006663744 -0600
@@ -1238,7 +1238,7 @@
 	/* Look up names */
 
 	num_names = argc - 2;
-	names = (const char **)talloc(mem_ctx, sizeof(char *) * num_names);
+	names = TALLOC_ARRAY(mem_ctx, const char *, num_names);
 
 	for (i = 0; i < argc - 2; i++)
 		names[i] = argv[i + 2];
@@ -1296,7 +1296,7 @@
 	/* Look up rids */
 
 	num_rids = argc - 1;
-	rids = (uint32 *)talloc(mem_ctx, sizeof(uint32) * num_rids);
+	rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids);
 
 	for (i = 0; i < argc - 1; i++)
                 sscanf(argv[i + 1], "%i", &rids[i]);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpcclient/cmd_spoolss.c samba-3.0.9/source/rpcclient/cmd_spoolss.c
--- samba-3.0.9-orig/source/rpcclient/cmd_spoolss.c	2004-11-15 21:03:12.000000000 -0600
+++ samba-3.0.9/source/rpcclient/cmd_spoolss.c	2004-12-09 09:00:27.003664489 -0600
@@ -1333,7 +1333,7 @@
 	/* allocate the space; add one extra slot for a terminating NULL.
 	   Each filename is NULL terminated and the end contains a double
 	   NULL */
-	if ((info->dependentfiles=(uint16*)talloc(mem_ctx, (len+1)*sizeof(uint16))) == NULL)
+	if ((info->dependentfiles=TALLOC_ARRAY(mem_ctx, uint16, len+1)) == NULL)
 	{
 		DEBUG(0,("init_drv_info_3_members: Unable to malloc memory for dependenfiles\n"));
 		return False;
@@ -2035,7 +2035,7 @@
 	fstrcpy(value.valuename, argv[2]);
 	value.type = REG_SZ;
 	value.size = data.uni_str_len * 2;
-	value.data_p = talloc_memdup(mem_ctx, data.buffer, value.size);
+	value.data_p = TALLOC_MEMDUP(mem_ctx, data.buffer, value.size);
 
 	result = cli_spoolss_setprinterdata(cli, mem_ctx, &pol, &value);
 		
@@ -2417,8 +2417,7 @@
 	option.option_type_ptr = 1;
 	option.count = option.ctr.count = 2;
 
-	option.ctr.type = (SPOOL_NOTIFY_OPTION_TYPE *)talloc(
-		mem_ctx, sizeof(SPOOL_NOTIFY_OPTION_TYPE) * 2);
+	option.ctr.type = TALLOC_ARRAY(mem_ctx, SPOOL_NOTIFY_OPTION_TYPE, 2);
 
 	ZERO_STRUCT(option.ctr.type[0]);
 	option.ctr.type[0].type = PRINTER_NOTIFY_TYPE;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpcclient/rpcclient.c samba-3.0.9/source/rpcclient/rpcclient.c
--- samba-3.0.9-orig/source/rpcclient/rpcclient.c	2004-11-15 21:03:12.000000000 -0600
+++ samba-3.0.9/source/rpcclient/rpcclient.c	2004-12-09 09:00:26.999665482 -0600
@@ -59,10 +59,10 @@
 	if (!commands) 
 		return NULL;
 
-	matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
+	matches = SMB_MALLOC_ARRAY(char *, MAX_COMPLETIONS);
 	if (!matches) return NULL;
 
-	matches[count++] = strdup(text);
+	matches[count++] = SMB_STRDUP(text);
 	if (!matches[0]) return NULL;
 
 	while (commands && count < MAX_COMPLETIONS-1) 
@@ -78,7 +78,7 @@
                       ( commands->cmd_set[i].returntype == RPC_RTYPE_WERROR &&
                         commands->cmd_set[i].wfn)))
 			{
-				matches[count] = strdup(commands->cmd_set[i].name);
+				matches[count] = SMB_STRDUP(commands->cmd_set[i].name);
 				if (!matches[count]) 
 					return NULL;
 				count++;
@@ -91,7 +91,7 @@
 
 	if (count == 2) {
 		SAFE_FREE(matches[0]);
-		matches[0] = strdup(matches[1]);
+		matches[0] = SMB_STRDUP(matches[1]);
 	}
 	matches[count] = NULL;
 	return matches;
@@ -485,7 +485,7 @@
 {
 	struct cmd_list *entry;
 
-	if (!(entry = (struct cmd_list *)malloc(sizeof(struct cmd_list)))) {
+	if (!(entry = SMB_MALLOC_P(struct cmd_list))) {
 		DEBUG(0, ("out of memory\n"));
 		return;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_client/cli_ds.c samba-3.0.9/source/rpc_client/cli_ds.c
--- samba-3.0.9-orig/source/rpc_client/cli_ds.c	2004-11-15 21:03:12.000000000 -0600
+++ samba-3.0.9/source/rpc_client/cli_ds.c	2004-12-09 09:00:26.995666476 -0600
@@ -39,8 +39,13 @@
 
 	/* Initialise parse structures */
 
-	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
-	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+	if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+		return NT_STATUS_NO_MEMORY;
+	}
+	if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+		prs_mem_free(&qbuf);
+		return NT_STATUS_NO_MEMORY;
+	}
 	
 	q.level = level;
 	
@@ -63,7 +68,7 @@
 	result = r.status;
 
 	if ( r.ptr && ctr ) {
-		ctr->basic = talloc(mem_ctx, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
+		ctr->basic = TALLOC_P(mem_ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC);
 		if (!ctr->basic)
 			goto done;
 		memcpy(ctr->basic, r.info.basic, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
@@ -94,8 +99,13 @@
 
 	/* Initialise parse structures */
 
-	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
-	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+	if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+		return NT_STATUS_NO_MEMORY;;
+	}
+	if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+		prs_mem_free(&qbuf);
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	init_q_ds_enum_domain_trusts( &q, server, flags );
 		
@@ -118,7 +128,7 @@
 		int i;
 	
 		*num_domains = r.num_domains;
-		*trusts = (struct ds_domain_trust*)talloc(mem_ctx, r.num_domains*sizeof(**trusts));
+		*trusts = TALLOC_ARRAY(mem_ctx, struct ds_domain_trust, r.num_domains);
 
 		for ( i=0; i< *num_domains; i++ ) {
 			(*trusts)[i].flags = r.domains.trusts[i].flags;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_client/cli_echo.c samba-3.0.9/source/rpc_client/cli_echo.c
--- samba-3.0.9-orig/source/rpc_client/cli_echo.c	2004-11-15 21:03:12.000000000 -0600
+++ samba-3.0.9/source/rpc_client/cli_echo.c	2004-12-09 09:00:26.980670202 -0600
@@ -35,8 +35,13 @@
 
 	/* Initialise parse structures */
 
-	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
-	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+	if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+		return NT_STATUS_NO_MEMORY;
+	}
+	if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+		prs_mem_free(&qbuf);
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	/* Marshall data and send request */
 
@@ -76,8 +81,13 @@
 
 	/* Initialise parse structures */
 
-	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
-	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+	if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+		return NT_STATUS_NO_MEMORY;
+	}
+	if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+		prs_mem_free(&qbuf);
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	/* Marshall data and send request */
 
@@ -95,7 +105,7 @@
 	result = True;
 
 	if (out_data) {
-		*out_data = talloc(mem_ctx, size);
+		*out_data = TALLOC(mem_ctx, size);
 		memcpy(*out_data, r.data, size);
 	}
 
@@ -119,8 +129,13 @@
 
 	/* Initialise parse structures */
 
-	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
-	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+	if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+		return NT_STATUS_NO_MEMORY;
+	}
+	if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+		prs_mem_free(&qbuf);
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	/* Marshall data and send request */
 
@@ -159,8 +174,13 @@
 
 	/* Initialise parse structures */
 
-	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
-	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+	if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+		return NT_STATUS_NO_MEMORY;
+	}
+	if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+		prs_mem_free(&qbuf);
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	/* Marshall data and send request */
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_client/cli_lsarpc.c samba-3.0.9/source/rpc_client/cli_lsarpc.c
--- samba-3.0.9-orig/source/rpc_client/cli_lsarpc.c	2004-11-15 21:03:12.000000000 -0600
+++ samba-3.0.9/source/rpc_client/cli_lsarpc.c	2004-12-09 09:00:26.990667718 -0600
@@ -88,7 +88,7 @@
 	if (NT_STATUS_IS_OK(result = r.status)) {
 		*pol = r.pol;
 #ifdef __INSURE__
-		pol->marker = malloc(1);
+		pol->marker = MALLOC(1);
 #endif
 	}
 
@@ -276,22 +276,19 @@
 		goto done;
 	}
 
-	if (!((*domains) = (char **)talloc(mem_ctx, sizeof(char *) *
-					   num_sids))) {
+	if (!((*domains) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
 		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
 		result = NT_STATUS_UNSUCCESSFUL;
 		goto done;
 	}
 
-	if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) *
-					 num_sids))) {
+	if (!((*names) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
 		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
 		result = NT_STATUS_UNSUCCESSFUL;
 		goto done;
 	}
 
-	if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
-					  num_sids))) {
+	if (!((*types) = TALLOC_ARRAY(mem_ctx, uint32, num_sids))) {
 		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
 		result = NT_STATUS_UNSUCCESSFUL;
 		goto done;
@@ -393,15 +390,13 @@
 		goto done;
 	}
 
-	if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
-					 num_names)))) {
+	if (!((*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_names)))) {
 		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
 		result = NT_STATUS_UNSUCCESSFUL;
 		goto done;
 	}
 
-	if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
-					 num_names)))) {
+	if (!((*types = TALLOC_ARRAY(mem_ctx, uint32, num_names)))) {
 		DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
 		result = NT_STATUS_UNSUCCESSFUL;
 		goto done;
@@ -491,7 +486,7 @@
 		}
 
 		if (domain_sid && (r.dom.id3.buffer_dom_sid != 0)) {
-			*domain_sid = talloc(mem_ctx, sizeof(**domain_sid));
+			*domain_sid = TALLOC_P(mem_ctx, DOM_SID);
 			if (*domain_sid) {
 				sid_copy(*domain_sid, &r.dom.id3.dom_sid.sid);
 			}
@@ -508,7 +503,7 @@
 		}
 			
 		if (domain_sid && (r.dom.id5.buffer_dom_sid != 0)) {
-			*domain_sid = talloc(mem_ctx, sizeof(**domain_sid));
+			*domain_sid = TALLOC_P(mem_ctx, DOM_SID);
 			if (*domain_sid) {
 				sid_copy(*domain_sid, &r.dom.id5.dom_sid.sid);
 			}
@@ -599,14 +594,14 @@
 	}
 	
 	if (domain_guid) {
-		*domain_guid = talloc(mem_ctx, sizeof(**domain_guid));
+		*domain_guid = TALLOC_P(mem_ctx, struct uuid);
 		memcpy(*domain_guid, 
 		       &r.info.dns_dom_info.dom_guid, 
 		       sizeof(struct uuid));
 	}
 
 	if (domain_sid && r.info.dns_dom_info.ptr_dom_sid != 0) {
-		*domain_sid = talloc(mem_ctx, sizeof(**domain_sid));
+		*domain_sid = TALLOC_P(mem_ctx, DOM_SID);
 		if (*domain_sid) {
 			sid_copy(*domain_sid, 
 				 &r.info.dns_dom_info.dom_sid.sid);
@@ -689,8 +684,7 @@
 
 		/* Allocate memory for trusted domain names and sids */
 
-		*domain_names = (char **)talloc(mem_ctx, sizeof(char *) *
-						r.num_domains);
+		*domain_names = TALLOC_ARRAY(mem_ctx, char *, r.num_domains);
 
 		if (!*domain_names) {
 			DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
@@ -698,8 +692,7 @@
 			goto done;
 		}
 
-		*domain_sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
-						 r.num_domains);
+		*domain_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.num_domains);
 		if (!domain_sids) {
 			DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
 			result = NT_STATUS_NO_MEMORY;
@@ -775,19 +768,19 @@
 	*enum_context = r.enum_context;
 	*count = r.count;
 
-	if (!((*privs_name = (char **)talloc(mem_ctx, sizeof(char *) * r.count)))) {
+	if (!((*privs_name = TALLOC_ARRAY(mem_ctx, char *, r.count)))) {
 		DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
 		result = NT_STATUS_UNSUCCESSFUL;
 		goto done;
 	}
 
-	if (!((*privs_high = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
+	if (!((*privs_high = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
 		DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
 		result = NT_STATUS_UNSUCCESSFUL;
 		goto done;
 	}
 
-	if (!((*privs_low = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
+	if (!((*privs_low = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
 		DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
 		result = NT_STATUS_UNSUCCESSFUL;
 		goto done;
@@ -912,7 +905,7 @@
 
 	/* Return output parameters */
 
-	*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.sids.num_entries);
+	*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.sids.num_entries);
 	if (!*sids) {
 		DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n"));
 		result = NT_STATUS_UNSUCCESSFUL;
@@ -1037,7 +1030,7 @@
 	if (r.count == 0)
 		goto done;
 
-	if (!((*set = (LUID_ATTR *)talloc(mem_ctx, sizeof(LUID_ATTR) * r.count)))) {
+	if (!((*set = TALLOC_ARRAY(mem_ctx, LUID_ATTR, r.count)))) {
 		DEBUG(0, ("(cli_lsa_enum_privsaccount): out of memory\n"));
 		result = NT_STATUS_UNSUCCESSFUL;
 		goto done;
@@ -1206,7 +1199,7 @@
 		goto done;
 	}
 
-	*privs_name = (char **)talloc(mem_ctx, (*count) * sizeof(char **));
+	*privs_name = TALLOC_ARRAY(mem_ctx, char *, *count);
 	for (i=0;i<*count;i++) {
 		pull_ucs2_talloc(mem_ctx, &(*privs_name)[i], r.rights.strings[i].string.buffer);
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_client/cli_samr.c samba-3.0.9/source/rpc_client/cli_samr.c
--- samba-3.0.9-orig/source/rpc_client/cli_samr.c	2004-11-15 21:03:12.000000000 -0600
+++ samba-3.0.9/source/rpc_client/cli_samr.c	2004-12-09 09:00:26.987668463 -0600
@@ -853,13 +853,13 @@
 
 	if (r.num_entries2) {
 		/* allocate memory needed to return received data */	
-		*rids = (uint32*)talloc(mem_ctx, sizeof(uint32) * r.num_entries2);
+		*rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_entries2);
 		if (!*rids) {
 			DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
 			return NT_STATUS_NO_MEMORY;
 		}
 		
-		*dom_users = (char**)talloc(mem_ctx, sizeof(char*) * r.num_entries2);
+		*dom_users = TALLOC_ARRAY(mem_ctx, char*, r.num_entries2);
 		if (!*dom_users) {
 			DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
 			return NT_STATUS_NO_MEMORY;
@@ -931,8 +931,7 @@
 	if (*num_dom_groups == 0)
 		goto done;
 
-	if (!((*dom_groups) = (struct acct_info *)
-	      talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
+	if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) {
 		result = NT_STATUS_NO_MEMORY;
 		goto done;
 	}
@@ -1014,8 +1013,7 @@
 	if (*num_dom_aliases == 0)
 		goto done;
 
-	if (!((*dom_aliases) = (struct acct_info *)
-	      talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_aliases))) {
+	if (!((*dom_aliases) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_aliases))) {
 		result = NT_STATUS_NO_MEMORY;
 		goto done;
 	}
@@ -1096,7 +1094,7 @@
 		goto done;
 	}
 
-	if (!(*sids = talloc(mem_ctx, sizeof(DOM_SID) * *num_mem))) {
+	if (!(*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_mem))) {
 		result = NT_STATUS_UNSUCCESSFUL;
 		goto done;
 	}
@@ -1654,8 +1652,8 @@
 	}
 
 	*num_names = r.num_names1;
-	*names = talloc(mem_ctx, sizeof(char *) * r.num_names1);
-	*name_types = talloc(mem_ctx, sizeof(uint32) * r.num_names1);
+	*names = TALLOC_ARRAY(mem_ctx, char *, r.num_names1);
+	*name_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_names1);
 
 	for (i = 0; i < r.num_names1; i++) {
 		fstring tmp;
@@ -1724,8 +1722,8 @@
 	}
 
 	*num_rids = r.num_rids1;
-	*rids = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
-	*rid_types = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
+	*rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
+	*rid_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
 
 	for (i = 0; i < r.num_rids1; i++) {
 		(*rids)[i] = r.rids[i];
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_client/cli_spoolss.c samba-3.0.9/source/rpc_client/cli_spoolss.c
--- samba-3.0.9-orig/source/rpc_client/cli_spoolss.c	2004-11-15 21:03:12.000000000 -0600
+++ samba-3.0.9/source/rpc_client/cli_spoolss.c	2004-12-09 09:00:26.984669208 -0600
@@ -55,7 +55,7 @@
         uint32 i;
         PRINTER_INFO_0  *inf;
 
-        inf=(PRINTER_INFO_0 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_0));
+        inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_0, returned);
 	memset(inf, 0, returned*sizeof(PRINTER_INFO_0));
 
 	prs_set_offset(&buffer->prs,0);
@@ -75,7 +75,7 @@
         uint32 i;
         PRINTER_INFO_1  *inf;
 
-        inf=(PRINTER_INFO_1 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_1));
+        inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_1, returned);
 	memset(inf, 0, returned*sizeof(PRINTER_INFO_1));
 
 	prs_set_offset(&buffer->prs,0);
@@ -95,7 +95,7 @@
         uint32 i;
         PRINTER_INFO_2  *inf;
 
-        inf=(PRINTER_INFO_2 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_2));
+        inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_2, returned);
 	memset(inf, 0, returned*sizeof(PRINTER_INFO_2));
 
 	prs_set_offset(&buffer->prs,0);
@@ -117,7 +117,7 @@
         uint32 i;
         PRINTER_INFO_3  *inf;
 
-        inf=(PRINTER_INFO_3 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_3));
+        inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_3, returned);
 	memset(inf, 0, returned*sizeof(PRINTER_INFO_3));
 
 	prs_set_offset(&buffer->prs,0);
@@ -138,7 +138,7 @@
 	uint32 i;
 	PRINTER_INFO_7  *inf;
 
-	inf=(PRINTER_INFO_7 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_7));
+	inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_7, returned);
 	memset(inf, 0, returned*sizeof(PRINTER_INFO_7));
 
 	prs_set_offset(&buffer->prs,0);
@@ -159,7 +159,7 @@
         uint32 i;
         PORT_INFO_1 *inf;
 
-        inf=(PORT_INFO_1*)talloc(mem_ctx, returned*sizeof(PORT_INFO_1));
+        inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_1, returned);
 	memset(inf, 0, returned*sizeof(PORT_INFO_1));
 
         prs_set_offset(&buffer->prs, 0);
@@ -179,7 +179,7 @@
         uint32 i;
         PORT_INFO_2 *inf;
 
-        inf=(PORT_INFO_2*)talloc(mem_ctx, returned*sizeof(PORT_INFO_2));
+        inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_2, returned);
 	memset(inf, 0, returned*sizeof(PORT_INFO_2));
 
         prs_set_offset(&buffer->prs, 0);
@@ -199,7 +199,7 @@
         uint32 i;
         DRIVER_INFO_1 *inf;
 
-        inf=(DRIVER_INFO_1 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_1));
+        inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_1, returned);
 	memset(inf, 0, returned*sizeof(DRIVER_INFO_1));
 
 	prs_set_offset(&buffer->prs,0);
@@ -219,7 +219,7 @@
         uint32 i;
         DRIVER_INFO_2 *inf;
 
-        inf=(DRIVER_INFO_2 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_2));
+        inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_2, returned);
 	memset(inf, 0, returned*sizeof(DRIVER_INFO_2));
 
 	prs_set_offset(&buffer->prs,0);
@@ -239,7 +239,7 @@
         uint32 i;
         DRIVER_INFO_3 *inf;
 
-        inf=(DRIVER_INFO_3 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_3));
+        inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_3, returned);
 	memset(inf, 0, returned*sizeof(DRIVER_INFO_3));
 
 	prs_set_offset(&buffer->prs,0);
@@ -259,7 +259,7 @@
 {
 	DRIVER_DIRECTORY_1 *inf;
  
-        inf=(DRIVER_DIRECTORY_1 *)talloc(mem_ctx, sizeof(DRIVER_DIRECTORY_1));
+        inf=TALLOC_P(mem_ctx, DRIVER_DIRECTORY_1);
 	memset(inf, 0, sizeof(DRIVER_DIRECTORY_1));
 
         prs_set_offset(&buffer->prs, 0);
@@ -1499,7 +1499,7 @@
 {
 	int i;
 
-	*forms = (FORM_1 *)talloc(mem_ctx, num_forms * sizeof(FORM_1));
+	*forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms);
 	prs_set_offset(&buffer->prs,0);
 
 	for (i = 0; i < num_forms; i++)
@@ -1581,7 +1581,7 @@
 {
 	uint32 i;
 
-	*jobs = (JOB_INFO_1 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_1));
+	*jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs);
 	prs_set_offset(&buffer->prs,0);
 
 	for (i = 0; i < num_jobs; i++) 
@@ -1593,7 +1593,7 @@
 {
 	uint32 i;
 
-	*jobs = (JOB_INFO_2 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_2));
+	*jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs);
 	prs_set_offset(&buffer->prs,0);
 
 	for (i = 0; i < num_jobs; i++) 
@@ -2016,7 +2016,7 @@
 
 	/* Return output parameters */
 
-	value->data_p = talloc_memdup(mem_ctx, r.data, r.needed);
+	value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed);
 	value->type = r.type;
 	value->size = r.size;
 
@@ -2071,7 +2071,7 @@
 
 	/* Return output parameters */
 
-	value->data_p = talloc_memdup(mem_ctx, r.data, r.needed);
+	value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed);
 	value->type = r.type;
 	value->size = r.needed;
 
@@ -2226,7 +2226,7 @@
 	if (value) {
 		rpcstr_pull(value->valuename, r.value, sizeof(value->valuename), -1,
 			    STR_TERMINATE);
-		value->data_p = talloc_memdup(mem_ctx, r.data, r.realdatasize);
+		value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.realdatasize);
 		value->type = r.type;
 		value->size = r.realdatasize;
 	}
@@ -2483,7 +2483,7 @@
 	/* Copy results */
 	
 	if (keylist) {
-		*keylist = (uint16 *)malloc(r.keys.buf_len * 2);
+		*keylist = SMB_MALLOC_ARRAY(uint16, r.keys.buf_len);
 		memcpy(*keylist, r.keys.buffer, r.keys.buf_len * 2);
 		if (len)
 			*len = r.keys.buf_len * 2;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_client/cli_srvsvc.c samba-3.0.9/source/rpc_client/cli_srvsvc.c
--- samba-3.0.9-orig/source/rpc_client/cli_srvsvc.c	2004-11-15 21:03:12.000000000 -0600
+++ samba-3.0.9/source/rpc_client/cli_srvsvc.c	2004-12-09 09:00:26.992667221 -0600
@@ -120,8 +120,7 @@
 
 	switch(info_level) {
 	case 1:
-		ctr->share.info1 = (SRV_SHARE_INFO_1 *)talloc(
-			mem_ctx, sizeof(SRV_SHARE_INFO_1) * ctr->num_entries);
+		ctr->share.info1 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_1, ctr->num_entries);
 		
 		memset(ctr->share.info1, 0, sizeof(SRV_SHARE_INFO_1));
 
@@ -148,8 +147,7 @@
 
 		break;
 	case 2:
-		ctr->share.info2 = (SRV_SHARE_INFO_2 *)talloc(
-			mem_ctx, sizeof(SRV_SHARE_INFO_2) * ctr->num_entries);
+		ctr->share.info2 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_2, ctr->num_entries);
 		
 		memset(ctr->share.info2, 0, sizeof(SRV_SHARE_INFO_2));
 
@@ -183,8 +181,7 @@
 		break;
 	/* adding info-level 502 here */
 	case 502:
-		ctr->share.info502 = (SRV_SHARE_INFO_502 *)talloc(
-			mem_ctx, sizeof(SRV_SHARE_INFO_502) * ctr->num_entries);
+		ctr->share.info502 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_502, ctr->num_entries);
 		
 		memset(ctr->share.info502, 0, sizeof(SRV_SHARE_INFO_502));
 
@@ -492,8 +489,7 @@
 	
 	switch(file_level) {
 	case 3:
-		ctr->file.info3 = (SRV_FILE_INFO_3 *)talloc(
-			mem_ctx, sizeof(SRV_FILE_INFO_3) * ctr->num_entries);
+		ctr->file.info3 = TALLOC_ARRAY(mem_ctx, SRV_FILE_INFO_3, ctr->num_entries);
 
 		memset(ctr->file.info3, 0, 
 		       sizeof(SRV_FILE_INFO_3) * ctr->num_entries);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_parse/parse_dfs.c samba-3.0.9/source/rpc_parse/parse_dfs.c
--- samba-3.0.9-orig/source/rpc_parse/parse_dfs.c	2004-11-15 21:03:24.000000000 -0600
+++ samba-3.0.9/source/rpc_parse/parse_dfs.c	2004-12-09 09:00:27.420560914 -0600
@@ -374,7 +374,7 @@
 		depth++;
 		/* should depend on whether marshalling or unmarshalling! */
 		if(UNMARSHALLING(ps)) {
-			ctr->dfs.info1 = (DFS_INFO_1 *)prs_alloc_mem(ps, sizeof(DFS_INFO_1)*num_entries);
+			ctr->dfs.info1 = PRS_ALLOC_MEM(ps, DFS_INFO_1, num_entries);
 			if (!ctr->dfs.info1)
 				return False;
 		}
@@ -394,7 +394,7 @@
 	case 2:
 		depth++;
 		if(UNMARSHALLING(ps)) {
-			ctr->dfs.info2 = (DFS_INFO_2 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_2));
+			ctr->dfs.info2 = PRS_ALLOC_MEM(ps, DFS_INFO_2, num_entries);
 			if (!ctr->dfs.info2)
 				return False;
 		}
@@ -424,7 +424,7 @@
 	case 3:
 		depth++;
 		if(UNMARSHALLING(ps)) {
-			ctr->dfs.info3 = (DFS_INFO_3 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_3));
+			ctr->dfs.info3 = PRS_ALLOC_MEM(ps, DFS_INFO_3, num_entries);
 			if (!ctr->dfs.info3)
 				return False;
 		}
@@ -517,7 +517,7 @@
 	depth++;
 
 	if(UNMARSHALLING(ps)) {
-		info3->storages = (DFS_STORAGE_INFO *)prs_alloc_mem(ps, info3->num_storage_infos*sizeof(DFS_STORAGE_INFO));
+		info3->storages = PRS_ALLOC_MEM(ps, DFS_STORAGE_INFO, info3->num_storage_infos);
 		if (!info3->storages)
 			return False;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_parse/parse_ds.c samba-3.0.9/source/rpc_parse/parse_ds.c
--- samba-3.0.9-orig/source/rpc_parse/parse_ds.c	2004-11-15 21:03:24.000000000 -0600
+++ samba-3.0.9/source/rpc_parse/parse_ds.c	2004-12-09 09:00:27.411563149 -0600
@@ -29,7 +29,7 @@
 	DSROLE_PRIMARY_DOMAIN_INFO_BASIC *p = *basic;
 	
 	if ( UNMARSHALLING(ps) )
-		p = *basic = (DSROLE_PRIMARY_DOMAIN_INFO_BASIC *)prs_alloc_mem(ps, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
+		p = *basic = PRS_ALLOC_MEM(ps, DSROLE_PRIMARY_DOMAIN_INFO_BASIC, 1);
 		
 	if ( !p )
 		return False;
@@ -208,7 +208,7 @@
 	
 	/* allocate the domain trusts array are parse it */
 	
-	ctr->trusts = (DS_DOMAIN_TRUSTS*)talloc(ps->mem_ctx, sizeof(DS_DOMAIN_TRUSTS)*ctr->max_count);
+	ctr->trusts = TALLOC_ARRAY(ps->mem_ctx, DS_DOMAIN_TRUSTS, ctr->max_count);
 	
 	if ( !ctr->trusts )
 		return False;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_parse/parse_echo.c samba-3.0.9/source/rpc_parse/parse_echo.c
--- samba-3.0.9-orig/source/rpc_parse/parse_echo.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/rpc_parse/parse_echo.c	2004-12-09 09:00:27.422560417 -0600
@@ -67,7 +67,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps)) {
-		q_d->data = prs_alloc_mem(ps, q_d->size);
+		q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
 
 		if (!q_d->data)
 			return False;
@@ -86,7 +86,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps)) {
-		q_d->data = prs_alloc_mem(ps, q_d->size);
+		q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
 
 		if (!q_d->data)
 			return False;
@@ -114,7 +114,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps)) {
-		q_d->data = prs_alloc_mem(ps, q_d->size);
+		q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
 
 		if (!q_d->data)
 			return False;
@@ -153,7 +153,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps)) {
-		q_d->data = prs_alloc_mem(ps, q_d->size);
+		q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
 
 		if (!q_d->data)
 			return False;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_parse/parse_lsa.c samba-3.0.9/source/rpc_parse/parse_lsa.c
--- samba-3.0.9-orig/source/rpc_parse/parse_lsa.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/rpc_parse/parse_lsa.c	2004-12-09 09:00:27.425559672 -0600
@@ -251,7 +251,7 @@
 
 	if (attr->ptr_sec_qos != 0) {
 		if (UNMARSHALLING(ps))
-			if (!(attr->sec_qos = (LSA_SEC_QOS *)prs_alloc_mem(ps,sizeof(LSA_SEC_QOS))))
+			if (!(attr->sec_qos = PRS_ALLOC_MEM(ps,LSA_SEC_QOS,1)))
 				return False;
 
 		if(!lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth))
@@ -540,17 +540,17 @@
 		 * allocating empty arrays of unicode headers, strings
 		 * and sids of enumerated trusted domains
 		 */
-		if (!(r_e->hdr_domain_name = (UNIHDR2 *)talloc(ctx,sizeof(UNIHDR2) * num_domains))) {
+		if (!(r_e->hdr_domain_name = TALLOC_ARRAY(ctx,UNIHDR2,num_domains))) {
 			r_e->status = NT_STATUS_NO_MEMORY;
 			return;
 		}
 		
-		if (!(r_e->uni_domain_name = (UNISTR2 *)talloc(ctx,sizeof(UNISTR2) * num_domains))) {
+		if (!(r_e->uni_domain_name = TALLOC_ARRAY(ctx,UNISTR2,num_domains))) {
 			r_e->status = NT_STATUS_NO_MEMORY;
 			return;
 		}
 
-		if (!(r_e->domain_sid = (DOM_SID2 *)talloc(ctx,sizeof(DOM_SID2) * num_domains))) {
+		if (!(r_e->domain_sid = TALLOC_ARRAY(ctx,DOM_SID2,num_domains))) {
 			r_e->status = NT_STATUS_NO_MEMORY;
 			return;
 		}
@@ -596,13 +596,13 @@
 		num_domains = r_e->num_domains2;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(r_e->hdr_domain_name = (UNIHDR2 *)prs_alloc_mem(ps,sizeof(UNIHDR2) * num_domains)))
+			if (!(r_e->hdr_domain_name = PRS_ALLOC_MEM(ps,UNIHDR2,num_domains)))
 				return False;
 
-			if (!(r_e->uni_domain_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2) * num_domains)))
+			if (!(r_e->uni_domain_name = PRS_ALLOC_MEM(ps,UNISTR2,num_domains)))
 				return False;
 
-			if (!(r_e->domain_sid = (DOM_SID2 *)prs_alloc_mem(ps,sizeof(DOM_SID2) * num_domains)))
+			if (!(r_e->domain_sid = PRS_ALLOC_MEM(ps,DOM_SID2,num_domains)))
 				return False;
 		}
 
@@ -697,7 +697,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps)) {
-		d_q->auditsettings = (uint32 *)talloc_zero(ps->mem_ctx, d_q->count2 * sizeof(uint32));
+		d_q->auditsettings = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
 	}
 
 	if (d_q->auditsettings == NULL) {
@@ -818,14 +818,12 @@
 
 	if (num_entries == 0) return;
 
-	if ((sen->ptr_sid = (uint32 *)talloc_zero(mem_ctx, num_entries * 
-					     sizeof(uint32))) == NULL) {
+	if ((sen->ptr_sid = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_entries )) == NULL) {
 		DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
 		return;
 	}
 
-	if ((sen->sid = (DOM_SID2 *)talloc_zero(mem_ctx, num_entries * 
-					   sizeof(DOM_SID2))) == NULL) {
+	if ((sen->sid = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID2, num_entries)) == NULL) {
 		DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
 		return;
 	}
@@ -872,15 +870,13 @@
 	/* Mallocate memory if we're unpacking from the wire */
 
 	if (UNMARSHALLING(ps)) {
-		if ((sen->ptr_sid = (uint32 *)prs_alloc_mem( ps,
-			sen->num_entries * sizeof(uint32))) == NULL) {
+		if ((sen->ptr_sid = PRS_ALLOC_MEM( ps, uint32, sen->num_entries)) == NULL) {
 			DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
 				  "ptr_sid\n"));
 			return False;
 		}
 
-		if ((sen->sid = (DOM_SID2 *)prs_alloc_mem( ps,
-			sen->num_entries * sizeof(DOM_SID2))) == NULL) {
+		if ((sen->sid = PRS_ALLOC_MEM( ps, DOM_SID2, sen->num_entries)) == NULL) {
 			DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
 				  "sids\n"));
 			return False;
@@ -980,15 +976,11 @@
 			return False;
 
 		if (UNMARSHALLING(ps)) {
-			if ((trn->name = (LSA_TRANS_NAME *)
-			     prs_alloc_mem(ps, trn->num_entries * 
-				    sizeof(LSA_TRANS_NAME))) == NULL) {
+			if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME, trn->num_entries)) == NULL) {
 				return False;
 			}
 
-			if ((trn->uni_name = (UNISTR2 *)
-			     prs_alloc_mem(ps, trn->num_entries *
-				    sizeof(UNISTR2))) == NULL) {
+			if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries)) == NULL) {
 				return False;
 			}
 		}
@@ -1068,14 +1060,12 @@
 	q_l->num_entries2 = num_names;
 	q_l->lookup_level = 1;
 
-	if ((q_l->uni_name = (UNISTR2 *)talloc_zero(
-		mem_ctx, num_names * sizeof(UNISTR2))) == NULL) {
+	if ((q_l->uni_name = TALLOC_ZERO_ARRAY(mem_ctx, UNISTR2, num_names)) == NULL) {
 		DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
 		return;
 	}
 
-	if ((q_l->hdr_name = (UNIHDR *)talloc_zero(
-		mem_ctx, num_names * sizeof(UNIHDR))) == NULL) {
+	if ((q_l->hdr_name = TALLOC_ZERO_ARRAY(mem_ctx, UNIHDR, num_names)) == NULL) {
 		DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
 		return;
 	}
@@ -1113,11 +1103,9 @@
 
 	if (UNMARSHALLING(ps)) {
 		if (q_r->num_entries) {
-			if ((q_r->hdr_name = (UNIHDR *)prs_alloc_mem(ps,
-					q_r->num_entries * sizeof(UNIHDR))) == NULL)
+			if ((q_r->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_r->num_entries)) == NULL)
 				return False;
-			if ((q_r->uni_name = (UNISTR2 *)prs_alloc_mem(ps,
-					q_r->num_entries * sizeof(UNISTR2))) == NULL)
+			if ((q_r->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_r->num_entries)) == NULL)
 				return False;
 		}
 	}
@@ -1187,7 +1175,7 @@
 		}
 
 		if (UNMARSHALLING(ps)) {
-			if ((r_r->dom_rid = (DOM_RID2 *)prs_alloc_mem(ps, r_r->num_entries2 * sizeof(DOM_RID2)))
+			if ((r_r->dom_rid = PRS_ALLOC_MEM(ps, DOM_RID2, r_r->num_entries2))
 			    == NULL) {
 				DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
 				return False;
@@ -1409,7 +1397,7 @@
 			return False;
 
 		if (UNMARSHALLING(ps))
-			if (!(r_q->privs = (LSA_PRIV_ENTRY *)prs_alloc_mem(ps, sizeof(LSA_PRIV_ENTRY) * r_q->count1)))
+			if (!(r_q->privs = PRS_ALLOC_MEM(ps, LSA_PRIV_ENTRY, r_q->count1)))
 				return False;
 
 		if (!lsa_io_priv_entries("", r_q->privs, r_q->count1, ps, depth))
@@ -1852,7 +1840,7 @@
 			if (!NT_STATUS_IS_OK(init_priv_with_ctx(ps->mem_ctx, &(r_c->set))))
 				return False;
 
-			if (!(r_c->set->set = (LUID_ATTR *)prs_alloc_mem(ps,sizeof(LUID_ATTR) * r_c->count)))
+			if (!(r_c->set->set = PRS_ALLOC_MEM(ps,LUID_ATTR,r_c->count)))
 				return False;
 
 		}
@@ -2022,7 +2010,7 @@
 		if (!NT_STATUS_IS_OK(init_priv_with_ctx(ps->mem_ctx, &(r_c->set))))
 			return False;
 		
-		if (!(r_c->set->set = (LUID_ATTR *)prs_alloc_mem(ps, sizeof(LUID_ATTR) * r_c->count)))
+		if (!(r_c->set->set = PRS_ALLOC_MEM(ps, LUID_ATTR, r_c->count)))
 			return False;
 	}
 	
@@ -2084,7 +2072,7 @@
 			if (!NT_STATUS_IS_OK(init_priv_with_ctx(ps->mem_ctx, &(r_c->set))))
 				return False;
 
-			if (!(r_c->set->set = (LUID_ATTR *)prs_alloc_mem(ps, sizeof(LUID_ATTR) * r_c->count)))
+			if (!(r_c->set->set = PRS_ALLOC_MEM(ps, LUID_ATTR, r_c->count)))
 				return False;
 		}
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_parse/parse_misc.c samba-3.0.9/source/rpc_parse/parse_misc.c
--- samba-3.0.9-orig/source/rpc_parse/parse_misc.c	2004-11-15 21:03:24.000000000 -0600
+++ samba-3.0.9/source/rpc_parse/parse_misc.c	2004-12-09 09:00:27.435557188 -0600
@@ -552,18 +552,14 @@
 		return;
 	}
 		
-
 	len = strlen(buf) + 1;
+	len = MAX(len,MAX_UNISTRLEN);
 
-	if (len < MAX_UNISTRLEN)
-		len = MAX_UNISTRLEN;
-	len *= sizeof(uint16);
-
-	str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
+	str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
 	if (str->buffer == NULL)
 		smb_panic("init_unistr: malloc fail\n");
 
-	rpcstr_push(str->buffer, buf, len, STR_TERMINATE);
+	rpcstr_push(str->buffer, buf, len*sizeof(uint16), STR_TERMINATE);
 }
 
 /*******************************************************************
@@ -591,10 +587,9 @@
 
 static void create_buffer3(BUFFER3 *str, size_t len)
 {
-	if (len < MAX_BUFFERLEN)
-		len = MAX_BUFFERLEN;
+	len = MAX(len,MAX_BUFFERLEN);
 
-    str->buffer = talloc_zero(get_talloc_ctx(), len);
+	str->buffer = TALLOC_ZERO(get_talloc_ctx(), len);
 	if (str->buffer == NULL)
 		smb_panic("create_buffer3: talloc fail\n");
 
@@ -683,7 +678,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps)) {
-		buf3->buffer = (unsigned char *)prs_alloc_mem(ps, buf3->buf_max_len);
+		buf3->buffer = PRS_ALLOC_MEM(ps, unsigned char, buf3->buf_max_len);
 		if (buf3->buffer == NULL)
 			return False;
 	}
@@ -735,9 +730,8 @@
 	str->buf_len = buf != NULL ? len : 0;
 
 	if (buf != NULL) {
-		if (len < MAX_BUFFERLEN)
-			len = MAX_BUFFERLEN;
-		str->buffer = talloc_zero(get_talloc_ctx(), len);
+		len = MAX(len,MAX_BUFFERLEN);
+		str->buffer = TALLOC_ZERO(get_talloc_ctx(), len);
 		if (str->buffer == NULL)
 			smb_panic("init_buffer2: talloc fail\n");
 		memcpy(str->buffer, buf, MIN(str->buf_len, len));
@@ -819,14 +813,9 @@
 	   (the the length of the source string) to prevent
 	   reallocation of memory. */
 	if (str->buffer == NULL) {
-		size_t len = from->uni_max_len * sizeof(uint16);
-
-		if (len < MAX_UNISTRLEN)
-			len = MAX_UNISTRLEN;
-		len *= sizeof(uint16);
-
-   		str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
-		if ((str->buffer == NULL) && (len > 0 )) {
+		size_t alloc_len = MAX(from->uni_max_len,MAX_UNISTRLEN);
+   		str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, alloc_len);
+		if ((str->buffer == NULL)) {
 			smb_panic("copy_unistr2: talloc fail\n");
 			return;
 		}
@@ -842,8 +831,6 @@
 
 void init_string2(STRING2 *str, const char *buf, int max_len, int str_len)
 {
-	int alloc_len = 0;
-
 	/* set up string lengths. */
 	str->str_max_len = max_len;
 	str->offset = 0;
@@ -851,9 +838,8 @@
 
 	/* store the string */
 	if(str_len != 0) {
-		if (str_len < MAX_STRINGLEN)
-			alloc_len = MAX_STRINGLEN;
-		str->buffer = talloc_zero(get_talloc_ctx(), alloc_len);
+		int alloc_len = MAX(str_len, MAX_STRINGLEN);
+		str->buffer = TALLOC_ZERO(get_talloc_ctx(), alloc_len);
 		if (str->buffer == NULL)
 			smb_panic("init_string2: malloc fail\n");
 		memcpy(str->buffer, buf, str_len);
@@ -917,16 +903,17 @@
 		len = strlen(buf) + 1;
 	}
 
-	if (len < MAX_UNISTRLEN)
-		len = MAX_UNISTRLEN;
-	len *= sizeof(uint16);
+	len = MAX(len,MAX_UNISTRLEN);
 
-	str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
-	if ((str->buffer == NULL) && (len > 0)) {
+	str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
+	if (str->buffer == NULL) {
 		smb_panic("init_unistr2: malloc fail\n");
 		return;
 	}
 
+	/* Ensure len is the length in *bytes* */
+	len *= sizeof(uint16);
+
 	/*
 	 * The UNISTR2 must be initialized !!!
 	 * jfm, 7/7/2001.
@@ -956,7 +943,6 @@
 void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
 {
 	uint32 len = strlen_w(buf);
-	uint32 max_len = len;
 	uint32 alloc_len;
 
 	ZERO_STRUCTP(str);
@@ -966,13 +952,10 @@
 	str->offset = 0;
 	str->uni_str_len = len;
 
-	if (max_len < MAX_UNISTRLEN)
-		max_len = MAX_UNISTRLEN;
-
-	alloc_len = (max_len + 1) * sizeof(uint16);
+	alloc_len = MAX((len + 1), MAX_UNISTRLEN);
 
-	str->buffer = (uint16 *)talloc_zero(ctx, alloc_len);
-	if ((str->buffer == NULL) && (alloc_len > 0)) {
+	str->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, alloc_len);
+	if (str->buffer == NULL) {
 		smb_panic("init_unistr2_w: malloc fail\n");
 		return;
 	}
@@ -1021,10 +1004,10 @@
 	to->uni_str_len = i;
 
 	/* allocate the space and copy the string buffer */
-	to->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), sizeof(uint16)*(to->uni_str_len));
+	to->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, i);
 	if (to->buffer == NULL)
 		smb_panic("init_unistr2_from_unistr: malloc fail\n");
-	memcpy(to->buffer, from->buffer, to->uni_max_len*sizeof(uint16));
+	memcpy(to->buffer, from->buffer, i*sizeof(uint16));
 	return;
 }
 
@@ -1111,7 +1094,7 @@
 		return True;
 	}
 
-	array->strings = (UNISTR2_ARRAY_EL *)talloc_zero(get_talloc_ctx(), count * sizeof(UNISTR2_ARRAY_EL));
+	array->strings = TALLOC_ZERO_ARRAY(get_talloc_ctx(), UNISTR2_ARRAY_EL, count );
 	if (!array->strings) {
 		return False;
 	}
@@ -1151,7 +1134,7 @@
 	}
 
 	if (UNMARSHALLING(ps)) {
-		array->strings = talloc_zero(get_talloc_ctx(), array->count * sizeof(array->strings[0]));
+		array->strings = TALLOC_ZERO_ARRAY(get_talloc_ctx(), UNISTR2_ARRAY_EL, array->count );
 	}
 	if (! array->strings) {
 		return False;
@@ -1637,7 +1620,7 @@
 
 void init_unistr3(UNISTR3 *str, const char *buf)
 {
-	size_t len;
+	size_t len, alloc_len;
 
 	if (buf == NULL) {
 		str->uni_str_len=0;
@@ -1649,16 +1632,13 @@
 
 	str->uni_str_len=len;
 
-	if (len < MAX_UNISTRLEN)
-		len = MAX_UNISTRLEN;
-
-	len *= sizeof(uint16);
+	alloc_len = MAX(len, MAX_UNISTRLEN);
 
-	str->str.buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
+	str->str.buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, alloc_len);
 	if (str->str.buffer == NULL)
 		smb_panic("init_unistr3: malloc fail\n");
 
-	rpcstr_push((char *)str->str.buffer, buf, len, STR_TERMINATE);
+	rpcstr_push((char *)str->str.buffer, buf, len * sizeof(uint16), STR_TERMINATE);
 }
 
 /*******************************************************************
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_parse/parse_net.c samba-3.0.9/source/rpc_parse/parse_net.c
--- samba-3.0.9-orig/source/rpc_parse/parse_net.c	2004-11-15 21:03:24.000000000 -0600
+++ samba-3.0.9/source/rpc_parse/parse_net.c	2004-12-09 09:00:27.431558181 -0600
@@ -1019,7 +1019,7 @@
 		}
 
 		/* Now allocate space for them. */
-		*ppsids = (DOM_SID2 *)talloc_zero(ctx, count * sizeof(DOM_SID2));
+		*ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
 		if (*ppsids == NULL)
 			return 0;
 
@@ -1310,7 +1310,7 @@
 	depth++;
 
 	if (UNMARSHALLING(ps)) {
-		ctr = *pp_ctr = (NET_ID_INFO_CTR *)prs_alloc_mem(ps, sizeof(NET_ID_INFO_CTR));
+		ctr = *pp_ctr = PRS_ALLOC_MEM(ps, NET_ID_INFO_CTR, 1);
 		if (ctr == NULL)
 			return False;
 	}
@@ -1481,7 +1481,7 @@
 
 	usr->num_groups2 = num_groups;
 
-	usr->gids = (DOM_GID *)talloc_zero(ctx,sizeof(DOM_GID) * (num_groups));
+	usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
 	if (usr->gids == NULL && num_groups>0)
 		return;
 
@@ -1614,7 +1614,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps) && usr->num_groups2 > 0) {
-		usr->gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_groups2);
+		usr->gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_groups2);
 		if (usr->gids == NULL)
 			return False;
 	}
@@ -1635,7 +1635,7 @@
 	if (usr->num_other_sids) {
 
 		if (UNMARSHALLING(ps)) {
-			usr->other_sids = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(DOM_SID2)*usr->num_other_sids);
+			usr->other_sids = PRS_ALLOC_MEM(ps, DOM_SID2, usr->num_other_sids);
 			if (usr->other_sids == NULL)
 				return False;
 		}
@@ -1644,7 +1644,7 @@
 			return False;
 
 		if (UNMARSHALLING(ps) && usr->num_other_groups > 0) {
-			usr->other_gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_other_groups);
+			usr->other_gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_other_groups);
 			if (usr->other_gids == NULL)
 				return False;
 		}
@@ -2322,8 +2322,7 @@
 			return False;
 		}
 
-                info->rids = talloc(ps->mem_ctx, sizeof(uint32) *
-                                    info->num_members2);
+                info->rids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members2);
 
                 if (info->rids == NULL) {
                         DEBUG(0, ("out of memory allocating %d rids\n",
@@ -2350,8 +2349,7 @@
 			return False;
 		}
 
-                info->attribs = talloc(ps->mem_ctx, sizeof(uint32) *
-                                       info->num_members3);
+                info->attribs = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members3);
 
                 if (info->attribs == NULL) {
                         DEBUG(0, ("out of memory allocating %d attribs\n",
@@ -2438,8 +2436,7 @@
 			return False;
 		}
 
-                info->ptr_sids = talloc(ps->mem_ctx, sizeof(uint32) *
-                                        info->num_sids);
+                info->ptr_sids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_sids);
                 
                 if (info->ptr_sids == NULL) {
                         DEBUG(0, ("out of memory allocating %d ptr_sids\n",
@@ -2454,8 +2451,7 @@
                                 return False;
 		}
 
-                info->sids = talloc(ps->mem_ctx, sizeof(DOM_SID2) *
-                                    info->num_sids);
+                info->sids = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, info->num_sids);
 
                 if (info->sids == NULL) {
                         DEBUG(0, ("error allocating %d sids\n",
@@ -2772,7 +2768,7 @@
 	if(!prs_uint32("attribute_count", ps, depth, &info->attribute_count))
                 return False;
 
-	info->attributes = talloc(ps->mem_ctx, sizeof(uint32) * info->attribute_count);
+	info->attributes = TALLOC_ARRAY(ps->mem_ctx, uint32, info->attribute_count);
 
 	for (i=0; i<info->attribute_count; i++)
 		if(!prs_uint32("attributes", ps, depth, &info->attributes[i]))
@@ -2781,8 +2777,8 @@
 	if(!prs_uint32("privlist_count", ps, depth, &info->privlist_count))
                 return False;
 
-	info->hdr_privslist = talloc(ps->mem_ctx, sizeof(UNIHDR) * info->privlist_count);
-	info->uni_privslist = talloc(ps->mem_ctx, sizeof(UNISTR2) * info->privlist_count);
+	info->hdr_privslist = TALLOC_ARRAY(ps->mem_ctx, UNIHDR, info->privlist_count);
+	info->uni_privslist = TALLOC_ARRAY(ps->mem_ctx, UNISTR2, info->privlist_count);
 
 	for (i=0; i<info->privlist_count; i++)
 		if(!smb_io_unihdr("hdr_privslist", &info->hdr_privslist[i], ps, depth))
@@ -2914,10 +2910,7 @@
 			}
 
                         if (r_s->num_deltas2 > 0) {
-                                r_s->hdr_deltas = (SAM_DELTA_HDR *)
-                                        talloc(ps->mem_ctx, r_s->num_deltas2 *
-                                               sizeof(SAM_DELTA_HDR));
-                          
+                                r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas2);
                                 if (r_s->hdr_deltas == NULL) {
                                         DEBUG(0, ("error tallocating memory "
                                                   "for %d delta headers\n", 
@@ -2935,10 +2928,7 @@
 			}
 
                         if (r_s->num_deltas2 > 0) {
-                                r_s->deltas = (SAM_DELTA_CTR *)
-                                        talloc(ps->mem_ctx, r_s->num_deltas2 *
-                                               sizeof(SAM_DELTA_CTR));
-
+                                r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas2);
                                 if (r_s->deltas == NULL) {
                                         DEBUG(0, ("error tallocating memory "
                                                   "for %d deltas\n", 
@@ -3050,9 +3040,7 @@
 		if (r_s->ptr_deltas != 0)
 		{
                         if (r_s->num_deltas > 0) {
-                                r_s->hdr_deltas = (SAM_DELTA_HDR *)
-                                        talloc(ps->mem_ctx, r_s->num_deltas *
-                                               sizeof(SAM_DELTA_HDR));
+                                r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas);
                                 if (r_s->hdr_deltas == NULL) {
                                         DEBUG(0, ("error tallocating memory "
                                                   "for %d delta headers\n", 
@@ -3068,10 +3056,7 @@
 			}
                         
                         if (r_s->num_deltas > 0) {
-                                r_s->deltas = (SAM_DELTA_CTR *)
-                                        talloc(ps->mem_ctx, r_s->num_deltas *
-                                               sizeof(SAM_DELTA_CTR));
-
+                                r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas);
                                 if (r_s->deltas == NULL) {
                                         DEBUG(0, ("error tallocating memory "
                                                   "for %d deltas\n", 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_parse/parse_prs.c samba-3.0.9/source/rpc_parse/parse_prs.c
--- samba-3.0.9-orig/source/rpc_parse/parse_prs.c	2004-11-15 21:03:24.000000000 -0600
+++ samba-3.0.9/source/rpc_parse/parse_prs.c	2004-12-09 09:00:27.409563646 -0600
@@ -105,7 +105,7 @@
 
 	if (size != 0) {
 		ps->buffer_size = size;
-		if((ps->data_p = (char *)malloc((size_t)size)) == NULL) {
+		if((ps->data_p = (char *)SMB_MALLOC((size_t)size)) == NULL) {
 			DEBUG(0,("prs_init: malloc fail for %u bytes.\n", (unsigned int)size));
 			return False;
 		}
@@ -143,14 +143,21 @@
  Allocate memory when unmarshalling... Always zero clears.
  ********************************************************************/
 
-char *prs_alloc_mem(prs_struct *ps, size_t size)
+#if defined(PARANOID_MALLOC_CHECKER)
+char *prs_alloc_mem_(prs_struct *ps, size_t size, unsigned int count)
+#else
+char *prs_alloc_mem(prs_struct *ps, size_t size, unsigned int count)
+#endif
 {
 	char *ret = NULL;
 
 	if (size) {
-		ret = talloc(ps->mem_ctx, size);
-		if (ret)
-			memset(ret, '\0', size);
+		/* We can't call the type-safe version here. */
+#if defined(PARANOID_MALLOC_CHECKER)
+		ret = talloc_zero_array_(ps->mem_ctx, size, count);
+#else
+		ret = talloc_zero_array(ps->mem_ctx, size, count);
+#endif
 	}
 	return ret;
 }
@@ -199,7 +206,7 @@
 		return prs_force_grow(ps, newsize - ps->buffer_size);
 
 	if (newsize < ps->buffer_size) {
-		char *new_data_p = Realloc(ps->data_p, newsize);
+		char *new_data_p = SMB_REALLOC(ps->data_p, newsize);
 		/* if newsize is zero, Realloc acts like free() & returns NULL*/
 		if (new_data_p == NULL && newsize != 0) {
 			DEBUG(0,("prs_set_buffer_size: Realloc failure for size %u.\n",
@@ -253,7 +260,7 @@
 
 		new_size = MAX(MAX_PDU_FRAG_LEN,extra_space);
 
-		if((new_data = malloc(new_size)) == NULL) {
+		if((new_data = SMB_MALLOC(new_size)) == NULL) {
 			DEBUG(0,("prs_grow: Malloc failure for size %u.\n", (unsigned int)new_size));
 			return False;
 		}
@@ -265,7 +272,7 @@
 		 */
 		new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);		
 
-		if ((new_data = Realloc(ps->data_p, new_size)) == NULL) {
+		if ((new_data = SMB_REALLOC(ps->data_p, new_size)) == NULL) {
 			DEBUG(0,("prs_grow: Realloc failure for size %u.\n",
 				(unsigned int)new_size));
 			return False;
@@ -296,7 +303,7 @@
 		return False;
 	}
 
-	if((new_data = Realloc(ps->data_p, new_size)) == NULL) {
+	if((new_data = SMB_REALLOC(ps->data_p, new_size)) == NULL) {
 		DEBUG(0,("prs_force_grow: Realloc failure for size %u.\n",
 			(unsigned int)new_size));
 		return False;
@@ -886,7 +893,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps)) {
-		str->buffer = (uint16 *)prs_alloc_mem(ps,str->buf_len * sizeof(uint16));
+		str->buffer = PRS_ALLOC_MEM(ps,uint16,str->buf_len);
 		if (str->buffer == NULL)
 			return False;
 	}
@@ -918,7 +925,7 @@
 
 	if (UNMARSHALLING(ps)) {
 		if ( str->buf_len ) {
-			str->buffer = (uint16 *)prs_alloc_mem(ps,str->buf_len);
+			str->buffer = PRS_ALLOC_MEM(ps, uint16, str->buf_len);
 			if ( str->buffer == NULL )
 				return False;
 		}
@@ -945,7 +952,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps)) {
-		str->buffer = (unsigned char *)prs_alloc_mem(ps,str->str_max_len);
+		str->buffer = PRS_ALLOC_MEM(ps,unsigned char, str->str_max_len);
 		if (str->buffer == NULL)
 			return False;
 	}
@@ -989,7 +996,7 @@
 		return True;
 
 	if (UNMARSHALLING(ps)) {
-		str->buffer = (uint16 *)prs_alloc_mem(ps,str->uni_max_len * sizeof(uint16));
+		str->buffer = PRS_ALLOC_MEM(ps,uint16,str->uni_max_len);
 		if (str->buffer == NULL)
 			return False;
 	}
@@ -1016,7 +1023,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps)) {
-		str->str.buffer = (uint16 *)prs_alloc_mem(ps,str->uni_str_len * sizeof(uint16));
+		str->str.buffer = PRS_ALLOC_MEM(ps,uint16,str->uni_str_len);
 		if (str->str.buffer == NULL)
 			return False;
 	}
@@ -1109,7 +1116,7 @@
 			alloc_len += 1;
 
 		/* should we allocate anything at all? */
-		str->buffer = (uint16 *)prs_alloc_mem(ps,alloc_len * sizeof(uint16));
+		str->buffer = PRS_ALLOC_MEM(ps,uint16,alloc_len);
 		if ((str->buffer == NULL) && (alloc_len > 0))
 			return False;
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_parse/parse_samr.c samba-3.0.9/source/rpc_parse/parse_samr.c
--- samba-3.0.9-orig/source/rpc_parse/parse_samr.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/rpc_parse/parse_samr.c	2004-12-09 09:00:27.463550233 -0600
@@ -1401,8 +1401,8 @@
 			return False;
 
 		if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
-			r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
-			r_u->uni_acct_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+			r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY, r_u->num_entries2);
+			r_u->uni_acct_name = PRS_ALLOC_MEM(ps,UNISTR2, r_u->num_entries2);
 		}
 
 		if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
@@ -1506,11 +1506,11 @@
 	if (num_entries==0)
 		return NT_STATUS_OK;
 
-	sam->sam=(SAM_ENTRY1 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY1));
+	sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY1, num_entries);
 	if (!sam->sam)
 		return NT_STATUS_NO_MEMORY;
 
-	sam->str=(SAM_STR1 *)talloc(ctx, num_entries*sizeof(SAM_STR1));
+	sam->str=TALLOC_ARRAY(ctx, SAM_STR1, num_entries);
 	if (!sam->str)
 		return NT_STATUS_NO_MEMORY;
 
@@ -1584,16 +1584,12 @@
 
 	if (UNMARSHALLING(ps) && num_entries > 0) {
 
-		if ((sam->sam = (SAM_ENTRY1 *)
-		     prs_alloc_mem(ps, sizeof(SAM_ENTRY1) *
-				   num_entries)) == NULL) {
+		if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY1, num_entries)) == NULL) {
 			DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
 			return False;
 		}
 
-		if ((sam->str = (SAM_STR1 *)
-		     prs_alloc_mem(ps, sizeof(SAM_STR1) * 
-				   num_entries)) == NULL) {
+		if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR1, num_entries)) == NULL) {
 			DEBUG(0, ("out of memory allocating SAM_STR1\n"));
 			return False;
 		}
@@ -1633,10 +1629,10 @@
 	if (num_entries==0)
 		return NT_STATUS_OK;
 
-	if (!(sam->sam=(SAM_ENTRY2 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY2))))
+	if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY2, num_entries)))
 		return NT_STATUS_NO_MEMORY;
 
-	if (!(sam->str=(SAM_STR2 *)talloc(ctx, num_entries*sizeof(SAM_STR2))))
+	if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR2, num_entries)))
 		return NT_STATUS_NO_MEMORY;
 
 	ZERO_STRUCTP(sam->sam);
@@ -1697,16 +1693,12 @@
 
 	if (UNMARSHALLING(ps) && num_entries > 0) {
 
-		if ((sam->sam = (SAM_ENTRY2 *)
-		     prs_alloc_mem(ps, sizeof(SAM_ENTRY2) *
-				   num_entries)) == NULL) {
+		if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY2, num_entries)) == NULL) {
 			DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
 			return False;
 		}
 
-		if ((sam->str = (SAM_STR2 *)
-		     prs_alloc_mem(ps, sizeof(SAM_STR2) * 
-				   num_entries)) == NULL) {
+		if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR2, num_entries)) == NULL) {
 			DEBUG(0, ("out of memory allocating SAM_STR2\n"));
 			return False;
 		}
@@ -1743,10 +1735,10 @@
 	if (num_entries==0)
 		return NT_STATUS_OK;
 
-	if (!(sam->sam=(SAM_ENTRY3 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY3))))
+	if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY3, num_entries)))
 		return NT_STATUS_NO_MEMORY;
 
-	if (!(sam->str=(SAM_STR3 *)talloc(ctx, num_entries*sizeof(SAM_STR3))))
+	if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR3, num_entries)))
 		return NT_STATUS_NO_MEMORY;
 
 	ZERO_STRUCTP(sam->sam);
@@ -1788,16 +1780,12 @@
 
 	if (UNMARSHALLING(ps) && num_entries > 0) {
 
-		if ((sam->sam = (SAM_ENTRY3 *)
-		     prs_alloc_mem(ps, sizeof(SAM_ENTRY3) *
-				   num_entries)) == NULL) {
+		if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY3, num_entries)) == NULL) {
 			DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
 			return False;
 		}
 
-		if ((sam->str = (SAM_STR3 *)
-		     prs_alloc_mem(ps, sizeof(SAM_STR3) * 
-				   num_entries)) == NULL) {
+		if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR3, num_entries)) == NULL) {
 			DEBUG(0, ("out of memory allocating SAM_STR3\n"));
 			return False;
 		}
@@ -1836,10 +1824,10 @@
 	if (num_entries==0)
 		return NT_STATUS_OK;
 
-	if (!(sam->sam=(SAM_ENTRY4 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY4))))
+	if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY4, num_entries)))
 		return NT_STATUS_NO_MEMORY;
 
-	if (!(sam->str=(SAM_STR4 *)talloc(ctx, num_entries*sizeof(SAM_STR4))))
+	if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR4, num_entries)))
 		return NT_STATUS_NO_MEMORY;
 
 	ZERO_STRUCTP(sam->sam);
@@ -1880,16 +1868,12 @@
 
 	if (UNMARSHALLING(ps) && num_entries > 0) {
 
-		if ((sam->sam = (SAM_ENTRY4 *)
-		     prs_alloc_mem(ps, sizeof(SAM_ENTRY4) *
-				   num_entries)) == NULL) {
+		if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY4, num_entries)) == NULL) {
 			DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
 			return False;
 		}
 
-		if ((sam->str = (SAM_STR4 *)
-		     prs_alloc_mem(ps, sizeof(SAM_STR4) * 
-				   num_entries)) == NULL) {
+		if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR4, num_entries)) == NULL) {
 			DEBUG(0, ("out of memory allocating SAM_STR4\n"));
 			return False;
 		}
@@ -1926,10 +1910,10 @@
 	if (num_entries==0)
 		return NT_STATUS_OK;
 
-	if (!(sam->sam=(SAM_ENTRY5 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY5))))
+	if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY5, num_entries)))
 		return NT_STATUS_NO_MEMORY;
 
-	if (!(sam->str=(SAM_STR5 *)talloc(ctx, num_entries*sizeof(SAM_STR5))))
+	if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR5, num_entries)))
 		return NT_STATUS_NO_MEMORY;
 
 	ZERO_STRUCTP(sam->sam);
@@ -1970,16 +1954,12 @@
 
 	if (UNMARSHALLING(ps) && num_entries > 0) {
 
-		if ((sam->sam = (SAM_ENTRY5 *)
-		     prs_alloc_mem(ps, sizeof(SAM_ENTRY5) *
-				   num_entries)) == NULL) {
+		if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY5, num_entries)) == NULL) {
 			DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
 			return False;
 		}
 
-		if ((sam->str = (SAM_STR5 *)
-		     prs_alloc_mem(ps, sizeof(SAM_STR5) * 
-				   num_entries)) == NULL) {
+		if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR5, num_entries)) == NULL) {
 			DEBUG(0, ("out of memory allocating SAM_STR5\n"));
 			return False;
 		}
@@ -2354,7 +2334,7 @@
 				prs_struct *ps, int depth)
 {
 	if (UNMARSHALLING(ps))
-		*ctr = (GROUP_INFO_CTR *)prs_alloc_mem(ps,sizeof(GROUP_INFO_CTR));
+		*ctr = PRS_ALLOC_MEM(ps,GROUP_INFO_CTR,1);
 
 	if (*ctr == NULL)
 		return False;
@@ -2929,7 +2909,7 @@
 			if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
 				return False;
 			if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
-				r_u->rid = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->rid[0])*r_u->num_rids);
+				r_u->rid = PRS_ALLOC_MEM(ps,uint32,r_u->num_rids);
 				if (r_u->rid == NULL)
 					return False;
 			}
@@ -2945,7 +2925,7 @@
 				return False;
 
 			if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
-				r_u->attr = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->attr[0])*r_u->num_attrs);
+				r_u->attr = PRS_ALLOC_MEM(ps,uint32,r_u->num_attrs);
 				if (r_u->attr == NULL)
 					return False;
 			}
@@ -3046,7 +3026,7 @@
 
 	if ((*num_gids) != 0) {
 		if (UNMARSHALLING(ps)) {
-			(*gid) = (DOM_GID *)prs_alloc_mem(ps,sizeof(DOM_GID)*(*num_gids));
+			(*gid) = PRS_ALLOC_MEM(ps,DOM_GID,*num_gids);
 		}
 
 		if ((*gid) == NULL) {
@@ -3201,8 +3181,8 @@
 			return False;
 
 		if (UNMARSHALLING(ps)) {
-			r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
-			r_u->uni_dom_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+			r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
+			r_u->uni_dom_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
 		}
 
 		if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
@@ -3340,8 +3320,8 @@
 			return False;
 
 		if (UNMARSHALLING(ps)) {
-			r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
-			r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+			r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
+			r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
 		}
 
 		if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
@@ -3474,8 +3454,8 @@
 			return False;
 
 		if (UNMARSHALLING(ps) && (r_u->num_entries2 > 0)) {
-			r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
-			r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+			r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
+			r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
 		}
 
 		if (r_u->num_entries2 != 0 && 
@@ -3832,11 +3812,11 @@
 		return False;
 
 	if (UNMARSHALLING(ps) && (q_u->num_sids2 != 0)) {
-		q_u->ptr_sid = (uint32 *)prs_alloc_mem(ps,sizeof(q_u->ptr_sid[0])*q_u->num_sids2);
+		q_u->ptr_sid = PRS_ALLOC_MEM(ps,uint32,q_u->num_sids2);
 		if (q_u->ptr_sid == NULL)
 			return False;
 
-		q_u->sid = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(q_u->sid[0]) * q_u->num_sids2);
+		q_u->sid = PRS_ALLOC_MEM(ps, DOM_SID2, q_u->num_sids2);
 		if (q_u->sid == NULL)
 			return False;
 	}
@@ -3907,7 +3887,7 @@
 	if ((*num_rids) != 0) {
 		if (UNMARSHALLING(ps)) {
 			/* reading */
-			(*rid) = (uint32 *)prs_alloc_mem(ps,sizeof(uint32)*(*num_rids));
+			(*rid) = PRS_ALLOC_MEM(ps,uint32, *num_rids);
 		}
 		if ((*rid) == NULL)
 			return False;
@@ -4038,7 +4018,7 @@
 	q_u->flags = flags;
 	q_u->ptr = 0;
 	q_u->num_rids2 = num_rids;
-	q_u->rid = (uint32 *)talloc_zero(ctx, num_rids * sizeof(q_u->rid[0]));
+	q_u->rid = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids );
 	if (q_u->rid == NULL) {
 		q_u->num_rids1 = 0;
 		q_u->num_rids2 = 0;
@@ -4082,7 +4062,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps) && (q_u->num_rids2 != 0)) {
-		q_u->rid = (uint32 *)prs_alloc_mem(ps, sizeof(q_u->rid[0])*q_u->num_rids2);
+		q_u->rid = PRS_ALLOC_MEM(ps, uint32, q_u->num_rids2);
 		if (q_u->rid == NULL)
 			return False;
 	}
@@ -4163,11 +4143,11 @@
 
 
 		if (UNMARSHALLING(ps) && (r_u->num_names2 != 0)) {
-			r_u->hdr_name = (UNIHDR *) prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->hdr_name[0]));
+			r_u->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, r_u->num_names2);
 			if (r_u->hdr_name == NULL)
 				return False;
 
-			r_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->uni_name[0]));
+			r_u->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, r_u->num_names2);
 			if (r_u->uni_name == NULL)
 				return False;
 		}
@@ -4198,7 +4178,7 @@
 			return False;
 
 		if (UNMARSHALLING(ps) && (r_u->num_types2 != 0)) {
-			r_u->type = (uint32 *)prs_alloc_mem(ps, r_u->num_types2 * sizeof(r_u->type[0]));
+			r_u->type = PRS_ALLOC_MEM(ps, uint32, r_u->num_types2);
 			if (r_u->type == NULL)
 				return False;
 		}
@@ -4624,7 +4604,7 @@
 		if(!prs_uint32("num_sids1", ps, depth, &r_u->num_sids1))
 			return False;
 
-		ptr_sid = talloc(ps->mem_ctx, sizeof(uint32) * r_u->num_sids1);
+		ptr_sid = TALLOC_ARRAY(ps->mem_ctx, uint32, r_u->num_sids1);
 		if (!ptr_sid) {
 			return False;
 		}
@@ -4636,7 +4616,7 @@
 		}
 		
 		if (UNMARSHALLING(ps)) {
-			r_u->sid = talloc(ps->mem_ctx, r_u->num_sids1 * sizeof(DOM_SID2));
+			r_u->sid = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, r_u->num_sids1);
 		}
 		
 		for (i = 0; i < r_u->num_sids1; i++) {
@@ -4674,10 +4654,10 @@
 	q_u->ptr = 0;
 	q_u->num_names2 = num_names;
 
-	if (!(q_u->hdr_name = (UNIHDR *)talloc_zero(ctx, num_names * sizeof(UNIHDR))))
+	if (!(q_u->hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR, num_names)))
 		return NT_STATUS_NO_MEMORY;
 
-	if (!(q_u->uni_name = (UNISTR2 *)talloc_zero(ctx, num_names * sizeof(UNISTR2))))
+	if (!(q_u->uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_names)))
 		return NT_STATUS_NO_MEMORY;
 
 	for (i = 0; i < num_names; i++) {
@@ -4722,10 +4702,8 @@
 		return False;
 
 	if (UNMARSHALLING(ps) && (q_u->num_names2 != 0)) {
-		q_u->hdr_name = (UNIHDR *)prs_alloc_mem(ps, sizeof(UNIHDR) *
-							q_u->num_names2);
-		q_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, sizeof(UNISTR2) *
-							 q_u->num_names2);
+		q_u->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_u->num_names2);
+		q_u->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_u->num_names2);
 		if (!q_u->hdr_name || !q_u->uni_name)
 			return False;
 	}
@@ -4765,9 +4743,9 @@
 		r_u->ptr_rids = 1;
 		r_u->num_rids2 = num_rids;
 
-		if (!(r_u->rids = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
+		if (!(r_u->rids = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
 			return NT_STATUS_NO_MEMORY;
-		if (!(r_u->types = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
+		if (!(r_u->types = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
 			return NT_STATUS_NO_MEMORY;
 
 		if (!r_u->rids || !r_u->types)
@@ -4834,7 +4812,7 @@
 		}
 
 		if (UNMARSHALLING(ps))
-			r_u->rids = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_rids2);
+			r_u->rids = PRS_ALLOC_MEM(ps, uint32, r_u->num_rids2);
 
 		if (!r_u->rids) {
 			DEBUG(0, ("NULL rids in samr_io_r_lookup_names\n"));
@@ -4863,7 +4841,7 @@
 		}
 
 		if (UNMARSHALLING(ps))
-			r_u->types = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_types2);
+			r_u->types = PRS_ALLOC_MEM(ps, uint32, r_u->num_types2);
 
 		if (!r_u->types) {
 			DEBUG(0, ("NULL types in samr_io_r_lookup_names\n"));
@@ -6282,7 +6260,7 @@
 
 	switch (switch_value) {
 	case 0x10:
-		ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_10));
+		ctr->info.id10 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_10);
 		if (ctr->info.id10 == NULL)
 			return NT_STATUS_NO_MEMORY;
 
@@ -6298,7 +6276,7 @@
 			expire.low = 0xffffffff;
 			expire.high = 0x7fffffff;
 
-			ctr->info.id = (SAM_USER_INFO_11 *) talloc_zero(ctx,sizeof(*ctr->info.id11));
+			ctr->info.id = TALLOC_ZERO_P(ctx,SAM_USER_INFO_11);
 			init_sam_user_info11(ctr->info.id11, &expire,
 					     "BROOKFIELDS$",	/* name */
 					     0x03ef,	/* user rid */
@@ -6309,7 +6287,7 @@
 		}
 #endif
 	case 0x12:
-		ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_12));
+		ctr->info.id12 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_12);
 		if (ctr->info.id12 == NULL)
 			return NT_STATUS_NO_MEMORY;
 
@@ -6318,7 +6296,7 @@
 	case 21:
 		{
 			SAM_USER_INFO_21 *cusr;
-			cusr = (SAM_USER_INFO_21 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_21));
+			cusr = TALLOC_ZERO_P(ctx,SAM_USER_INFO_21);
 			ctr->info.id21 = cusr;
 			if (ctr->info.id21 == NULL)
 				return NT_STATUS_NO_MEMORY;
@@ -6377,7 +6355,7 @@
 	depth++;
 
 	if (UNMARSHALLING(ps)) {
-		ctr = (SAM_USERINFO_CTR *)prs_alloc_mem(ps,sizeof(SAM_USERINFO_CTR));
+		ctr = PRS_ALLOC_MEM(ps,SAM_USERINFO_CTR,1);
 		if (ctr == NULL)
 			return False;
 		*ppctr = ctr;
@@ -6397,7 +6375,7 @@
 	switch (ctr->switch_value) {
 	case 0x10:
 		if (UNMARSHALLING(ps))
-			ctr->info.id10 = (SAM_USER_INFO_10 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_10));
+			ctr->info.id10 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_10,1);
 		if (ctr->info.id10 == NULL) {
 			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
 			return False;
@@ -6406,7 +6384,7 @@
 		break;
 	case 0x11:
 		if (UNMARSHALLING(ps))
-			ctr->info.id11 = (SAM_USER_INFO_11 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_11));
+			ctr->info.id11 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_11,1);
 
 		if (ctr->info.id11 == NULL) {
 			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6416,7 +6394,7 @@
 		break;
 	case 0x12:
 		if (UNMARSHALLING(ps))
-			ctr->info.id12 = (SAM_USER_INFO_12 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_12));
+			ctr->info.id12 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_12,1);
 
 		if (ctr->info.id12 == NULL) {
 			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6426,7 +6404,7 @@
 		break;
 	case 20:
 		if (UNMARSHALLING(ps))
-			ctr->info.id20 = (SAM_USER_INFO_20 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_20));
+			ctr->info.id20 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_20,1);
 
 		if (ctr->info.id20 == NULL) {
 			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6436,7 +6414,7 @@
 		break;
 	case 21:
 		if (UNMARSHALLING(ps))
-			ctr->info.id21 = (SAM_USER_INFO_21 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_21));
+			ctr->info.id21 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_21,1);
 
 		if (ctr->info.id21 == NULL) {
 			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6446,7 +6424,7 @@
 		break;
 	case 23:
 		if (UNMARSHALLING(ps))
-			ctr->info.id23 = (SAM_USER_INFO_23 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_23));
+			ctr->info.id23 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_23,1);
 
 		if (ctr->info.id23 == NULL) {
 			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6456,7 +6434,7 @@
 		break;
 	case 24:
 		if (UNMARSHALLING(ps))
-			ctr->info.id24 = (SAM_USER_INFO_24 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_24));
+			ctr->info.id24 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_24,1);
 
 		if (ctr->info.id24 == NULL) {
 			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -6466,7 +6444,7 @@
 		break;
 	case 25:
 		if (UNMARSHALLING(ps))
-			ctr->info.id25 = (SAM_USER_INFO_25 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_25));
+			ctr->info.id25 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_25,1);
 
 		if (ctr->info.id25 == NULL) {
 			DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
@@ -7356,7 +7334,7 @@
 	if(!prs_align(ps))
 		return False;
 
-	if ((q_u->ctr = (SAM_UNK_CTR *)prs_alloc_mem(ps, sizeof(SAM_UNK_CTR))) == NULL)
+	if ((q_u->ctr = PRS_ALLOC_MEM(ps, SAM_UNK_CTR, 1)) == NULL)
 		return False;
 	
 	switch (q_u->switch_value) {
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_parse/parse_sec.c samba-3.0.9/source/rpc_parse/parse_sec.c
--- samba-3.0.9-orig/source/rpc_parse/parse_sec.c	2004-11-15 21:03:24.000000000 -0600
+++ samba-3.0.9/source/rpc_parse/parse_sec.c	2004-12-09 09:00:27.412562901 -0600
@@ -129,7 +129,7 @@
 		/*
 		 * This is a read and we must allocate the stuct to read into.
 		 */
-		if((psa = (SEC_ACL *)prs_alloc_mem(ps, sizeof(SEC_ACL))) == NULL)
+		if((psa = PRS_ALLOC_MEM(ps, SEC_ACL, 1)) == NULL)
 			return False;
 		*ppsa = psa;
 	}
@@ -154,7 +154,7 @@
 		 * between a non-present DACL (allow all access) and a DACL with no ACE's
 		 * (allow no access).
 		 */
-		if((psa->ace = (SEC_ACE *)prs_alloc_mem(ps,sizeof(psa->ace[0]) * (psa->num_aces+1))) == NULL)
+		if((psa->ace = PRS_ALLOC_MEM(ps, SEC_ACE, psa->num_aces+1)) == NULL)
 			return False;
 	}
 
@@ -191,7 +191,7 @@
 
 	if (psd == NULL) {
 		if(UNMARSHALLING(ps)) {
-			if((psd = (SEC_DESC *)prs_alloc_mem(ps,sizeof(SEC_DESC))) == NULL)
+			if((psd = PRS_ALLOC_MEM(ps,SEC_DESC,1)) == NULL)
 				return False;
 			*ppsd = psd;
 		} else {
@@ -244,7 +244,7 @@
 
 		if (UNMARSHALLING(ps)) {
 			/* reading */
-			if((psd->owner_sid = (DOM_SID *)prs_alloc_mem(ps,sizeof(*psd->owner_sid))) == NULL)
+			if((psd->owner_sid = PRS_ALLOC_MEM(ps,DOM_SID,1)) == NULL)
 				return False;
 		}
 
@@ -265,7 +265,7 @@
 
 		if (UNMARSHALLING(ps)) {
 			/* reading */
-			if((psd->grp_sid = (DOM_SID *)prs_alloc_mem(ps,sizeof(*psd->grp_sid))) == NULL)
+			if((psd->grp_sid = PRS_ALLOC_MEM(ps,DOM_SID,1)) == NULL)
 				return False;
 		}
 
@@ -324,7 +324,7 @@
 	psdb = *ppsdb;
 
 	if (UNMARSHALLING(ps) && psdb == NULL) {
-		if((psdb = (SEC_DESC_BUF *)prs_alloc_mem(ps,sizeof(SEC_DESC_BUF))) == NULL)
+		if((psdb = PRS_ALLOC_MEM(ps,SEC_DESC_BUF,1)) == NULL)
 			return False;
 		*ppsdb = psdb;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_parse/parse_spoolss.c samba-3.0.9/source/rpc_parse/parse_spoolss.c
--- samba-3.0.9-orig/source/rpc_parse/parse_spoolss.c	2004-11-15 21:03:25.000000000 -0600
+++ samba-3.0.9/source/rpc_parse/parse_spoolss.c	2004-12-09 09:00:27.450553462 -0600
@@ -269,7 +269,7 @@
 
 	/* reading */
 	if (UNMARSHALLING(ps))
-		if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)prs_alloc_mem(ps,ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
+		if((ctr->type=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION_TYPE,ctr->count)) == NULL)
 			return False;
 		
 	/* the option type struct */
@@ -421,20 +421,20 @@
 
 	case NOTIFY_STRING:
 
-		if (UNMARSHALLING(ps)) {
-			data->notify_data.data.string = 
-				(uint16 *)prs_alloc_mem(ps, data->notify_data.data.length);
-
-			if (!data->notify_data.data.string) 
-				return False;
-		}
-
 		if (MARSHALLING(ps))
 			data->notify_data.data.length /= 2;
 
 		if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length))
 			return False;
 
+		if (UNMARSHALLING(ps)) {
+			data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16,
+								data->notify_data.data.length);
+
+			if (!data->notify_data.data.string) 
+				return False;
+		}
+
 		if (!prs_uint16uni(True, "string", ps, depth, data->notify_data.data.string,
 				   data->notify_data.data.length))
 			return False;
@@ -447,8 +447,8 @@
 	case NOTIFY_POINTER:
 
 		if (UNMARSHALLING(ps)) {
-			data->notify_data.data.string = 
-				(uint16 *)prs_alloc_mem(ps, data->notify_data.data.length);
+			data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16,
+								data->notify_data.data.length);
 
 			if (!data->notify_data.data.string) 
 				return False;
@@ -506,7 +506,7 @@
 
 			/* Tallocate memory for string */
 
-			data->notify_data.data.string = (uint16 *)prs_alloc_mem(ps, x * 2);
+			data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16, x * 2);
 			if (!data->notify_data.data.string) 
 				return False;
 
@@ -679,7 +679,7 @@
 	depth++;
 
 	if (UNMARSHALLING(ps)) {
-		devmode->devicename.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
+		devmode->devicename.buffer = PRS_ALLOC_MEM(ps, uint16, 32);
 		if (devmode->devicename.buffer == NULL)
 			return False;
 	}
@@ -745,7 +745,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps)) {
-		devmode->formname.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
+		devmode->formname.buffer = PRS_ALLOC_MEM(ps, uint16, 32);
 		if (devmode->formname.buffer == NULL)
 			return False;
 	}
@@ -810,7 +810,7 @@
 
 	if (devmode->driverextra!=0) {
 		if (UNMARSHALLING(ps)) {
-			devmode->private=(uint8 *)prs_alloc_mem(ps, devmode->driverextra*sizeof(uint8));
+			devmode->private=PRS_ALLOC_MEM(ps, uint8, devmode->driverextra);
 			if(devmode->private == NULL)
 				return False;
 			DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra)); 
@@ -856,7 +856,7 @@
 	/* so we have a DEVICEMODE to follow */		
 	if (UNMARSHALLING(ps)) {
 		DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
-		dm_c->devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE));
+		dm_c->devmode=PRS_ALLOC_MEM(ps,DEVICEMODE,1);
 		if(dm_c->devmode == NULL)
 			return False;
 	}
@@ -1010,7 +1010,7 @@
 	SPOOL_PRINTER_INFO_LEVEL_2 *inf;
 
 	/* allocate the necessary memory */
-	if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2)))) {
+	if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2))) {
 		DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
 		return False;
 	}
@@ -1064,7 +1064,7 @@
 	SPOOL_PRINTER_INFO_LEVEL_3 *inf;
 
 	/* allocate the necessary memory */
-	if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_3*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_3)))) {
+	if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_3))) {
 		DEBUG(0,("make_spoolss_printer_info_3: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_3 sruct!\n"));
 		return False;
 	}
@@ -1087,7 +1087,7 @@
 	SPOOL_PRINTER_INFO_LEVEL_7 *inf;
 
 	/* allocate the necessary memory */
-	if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_7*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_7)))) {
+	if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_7))) {
 		DEBUG(0,("make_spoolss_printer_info_7: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_7 struct!\n"));
 		return False;
 	}
@@ -1444,7 +1444,7 @@
 		return False;
 	
 	if (UNMARSHALLING(ps) && r_u->size) {
-		r_u->data = (unsigned char *)prs_alloc_mem(ps, r_u->size);
+		r_u->data = PRS_ALLOC_MEM(ps, unsigned char, r_u->size);
 		if(!r_u->data)
 			return False;
 	}
@@ -1885,7 +1885,7 @@
 	if (q_u->buffer_size!=0)
 	{
 		if (UNMARSHALLING(ps))
-			q_u->buffer=(uint8 *)prs_alloc_mem(ps,q_u->buffer_size*sizeof(uint8));
+			q_u->buffer=PRS_ALLOC_MEM(ps, uint8, q_u->buffer_size);
 		if(q_u->buffer == NULL)
 			return False;	
 		if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
@@ -1952,7 +1952,7 @@
 	if (q_u->option_ptr!=0) {
 	
 		if (UNMARSHALLING(ps))
-			if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
+			if((q_u->option=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION,1)) == NULL)
 				return False;
 	
 		if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
@@ -2003,7 +2003,7 @@
 	if (q_u->option_ptr!=0) {
 	
 		if (UNMARSHALLING(ps))
-			if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
+			if((q_u->option=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION,1)) == NULL)
 				return False;
 	
 		if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
@@ -2229,7 +2229,7 @@
 
 			/* Yes this should be malloc not talloc. Don't change. */
 
-			chaine.buffer = malloc((q-p+1)*sizeof(uint16));
+			chaine.buffer = SMB_MALLOC((q-p+1)*sizeof(uint16));
 			if (chaine.buffer == NULL)
 				return False;
 
@@ -2298,7 +2298,7 @@
 
 				/* Yes this should be realloc - it's freed below. JRA */
 
-				if((tc2=(uint16 *)Realloc(chaine2, realloc_size)) == NULL) {
+				if((tc2=(uint16 *)SMB_REALLOC(chaine2, realloc_size)) == NULL) {
 					SAFE_FREE(chaine2);
 					return False;
 				}
@@ -2314,7 +2314,7 @@
 		if (chaine2)
 		{
 			chaine2[l_chaine2] = '\0';
-			*string=(uint16 *)talloc_memdup(prs_get_mem_context(ps),chaine2,realloc_size);
+			*string=(uint16 *)TALLOC_MEMDUP(prs_get_mem_context(ps),chaine2,realloc_size);
 			SAFE_FREE(chaine2);
 		}
 
@@ -2442,7 +2442,7 @@
 			return False;
 
 		/* read the string */
-		if((*devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE))) == NULL)
+		if((*devmode=PRS_ALLOC_MEM(ps,DEVICEMODE,1)) == NULL)
 			return False;
 		if (!spoolss_io_devmode(desc, ps, depth, *devmode))
 			return False;
@@ -3114,7 +3114,7 @@
 	depth++;
 	
 	if (UNMARSHALLING(ps))
-		buffer = *pp_buffer = (NEW_BUFFER *)prs_alloc_mem(ps, sizeof(NEW_BUFFER));
+		buffer = *pp_buffer = PRS_ALLOC_MEM(ps, NEW_BUFFER, 1);
 
 	if (buffer == NULL)
 		return False;
@@ -4172,7 +4172,7 @@
 		
 		make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
 #if 1	/* JERRY TEST */
-		q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
+		q_u->secdesc_ctr = SMB_MALLOC_P(SEC_DESC_BUF);
 		if (!q_u->secdesc_ctr)
 			return False;
 		q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
@@ -4196,7 +4196,7 @@
 		
 		make_spoolss_printer_info_3 (mem_ctx, &q_u->info.info_3, info->printers_3);
 		
-		q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
+		q_u->secdesc_ctr = SMB_MALLOC_P(SEC_DESC_BUF);
 		if (!q_u->secdesc_ctr)
 			return False;
 		q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
@@ -5011,7 +5011,7 @@
 		case 1:
 		{
 			if (UNMARSHALLING(ps)) {
-				if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
+				if ((il->info_1=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_1,1)) == NULL)
 					return False;
 			}
 			if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
@@ -5024,7 +5024,7 @@
 		 */	
 		case 2:
 			if (UNMARSHALLING(ps)) {
-				if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
+				if ((il->info_2=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_2,1)) == NULL)
 					return False;
 			}
 			if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
@@ -5034,7 +5034,7 @@
 		case 3:
 		{
 			if (UNMARSHALLING(ps)) {
-				if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
+				if ((il->info_3=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_3,1)) == NULL)
 					return False;
 			}
 			if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
@@ -5043,7 +5043,7 @@
 		}
 		case 7:
 			if (UNMARSHALLING(ps))
-				if ((il->info_7=(SPOOL_PRINTER_INFO_LEVEL_7 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_7))) == NULL)
+				if ((il->info_7=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_7,1)) == NULL)
 					return False;
 			if (!spool_io_printer_info_level_7("", il->info_7, ps, depth))
 				return False;
@@ -5148,7 +5148,7 @@
 		
 	/* reading */
 	if (UNMARSHALLING(ps)) {
-		il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
+		il=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_DRIVER_INFO_LEVEL_3,1);
 		if(il == NULL)
 			return False;
 		*q_u=il;
@@ -5226,7 +5226,7 @@
 		
 	/* reading */
 	if (UNMARSHALLING(ps)) {
-		il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
+		il=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_DRIVER_INFO_LEVEL_6,1);
 		if(il == NULL)
 			return False;
 		*q_u=il;
@@ -5385,7 +5385,7 @@
 	while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
 		rpcstr_pull(f, src, sizeof(f)-1, -1, STR_TERMINATE);
 		src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
-		tar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
+		tar = SMB_REALLOC_ARRAY(*ar, fstring, n+2);
 		if (!tar)
 			return False;
 		else
@@ -5499,7 +5499,7 @@
 	BOOL		null_char = False;
 	SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
 
-	if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
+	if (!(inf=TALLOC_ZERO_P(mem_ctx, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3)))
 		return False;
 	
 	inf->cversion	= info3->version;
@@ -5562,8 +5562,7 @@
 {
 
 	buf5->buf_len = len;
-	if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
-	{
+	if((buf5->buffer=(uint16*)TALLOC_MEMDUP(mem_ctx, src, sizeof(uint16)*len)) == NULL) {
 		DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
 		return False;
 	}
@@ -5672,7 +5671,7 @@
 	
 	if (*asc==NULL)
 	{
-		*asc=(NT_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_3));
+		*asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_3);
 		if(*asc == NULL)
 			return False;
 		ZERO_STRUCTP(*asc);
@@ -5719,7 +5718,7 @@
 	
 	if (*asc==NULL)
 	{
-		*asc=(NT_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_6));
+		*asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_6);
 		if(*asc == NULL)
 			return False;
 		ZERO_STRUCTP(*asc);
@@ -5772,7 +5771,7 @@
 	if (*asc==NULL) {
 		DEBUGADD(8,("allocating memory\n"));
 
-		*asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2));
+		*asc=SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL_2);
 		if(*asc == NULL)
 			return False;
 		ZERO_STRUCTP(*asc);
@@ -6168,7 +6167,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps) && r_u->valuesize) {
-		r_u->value = (uint16 *)prs_alloc_mem(ps, r_u->valuesize * 2);
+		r_u->value = PRS_ALLOC_MEM(ps, uint16, r_u->valuesize);
 		if (!r_u->value) {
 			DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata value\n"));
 			return False;
@@ -6191,7 +6190,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps) && r_u->datasize) {
-		r_u->data = (uint8 *)prs_alloc_mem(ps, r_u->datasize);
+		r_u->data = PRS_ALLOC_MEM(ps, uint8, r_u->datasize);
 		if (!r_u->data) {
 			DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata data\n"));
 			return False;
@@ -6326,7 +6325,7 @@
 		case REG_MULTI_SZ:
             if (q_u->max_len) {
                 if (UNMARSHALLING(ps))
-    				q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
+    				q_u->data=PRS_ALLOC_MEM(ps, uint8, q_u->max_len);
     			if(q_u->data == NULL)
     				return False;
     			if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
@@ -6885,7 +6884,7 @@
 		if (src->size != POINTER) 
 			continue;
 		len = src->notify_data.data.length;
-		s = malloc(sizeof(uint16)*len);
+		s = SMB_MALLOC_ARRAY(uint16, len);
 		if (s == NULL) {
 			DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n"));
 			return False;
@@ -6914,7 +6913,7 @@
 	
 	if (dst->count) 
 	{
-		dst->data = malloc(dst->count * sizeof(SPOOL_NOTIFY_INFO_DATA));
+		dst->data = SMB_MALLOC_ARRAY(SPOOL_NOTIFY_INFO_DATA, dst->count);
 		
 		DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n",
 			dst->count));
@@ -7084,7 +7083,7 @@
 		return False;
 	
 	if (UNMARSHALLING(ps) && r_u->size) {
-		r_u->data = (unsigned char *)prs_alloc_mem(ps, r_u->size);
+		r_u->data = PRS_ALLOC_MEM(ps, unsigned char, r_u->size);
 		if(!r_u->data)
 			return False;
 	}
@@ -7142,7 +7141,7 @@
 		case 0x7:
 			if (q_u->max_len) {
 				if (UNMARSHALLING(ps))
-    					q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
+    					q_u->data=PRS_ALLOC_MEM(ps, uint8, q_u->max_len);
     				if(q_u->data == NULL)
     					return False;
     				if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
@@ -7350,8 +7349,7 @@
 	/* first loop to write basic enum_value information */
 	
 	if (UNMARSHALLING(ps)) {
-		ctr->values = (PRINTER_ENUM_VALUES *)prs_alloc_mem(
-			ps, ctr->size_of_array * sizeof(PRINTER_ENUM_VALUES));
+		ctr->values = PRS_ALLOC_MEM(ps, PRINTER_ENUM_VALUES, ctr->size_of_array);
 		if (!ctr->values)
 			return False;
 	}
@@ -7392,8 +7390,7 @@
 		
 		if ( ctr->values[i].data_len ) {
 			if ( UNMARSHALLING(ps) ) {
-				ctr->values[i].data = (uint8 *)prs_alloc_mem(
-					ps, ctr->values[i].data_len);
+				ctr->values[i].data = PRS_ALLOC_MEM(ps, uint8, ctr->values[i].data_len);
 				if (!ctr->values[i].data)
 					return False;
 			}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_parse/parse_srv.c samba-3.0.9/source/rpc_parse/parse_srv.c
--- samba-3.0.9-orig/source/rpc_parse/parse_srv.c	2004-11-15 21:03:24.000000000 -0600
+++ samba-3.0.9/source/rpc_parse/parse_srv.c	2004-12-09 09:00:27.418561410 -0600
@@ -783,7 +783,7 @@
 		int i;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(info0 = (SRV_SHARE_INFO_0 *)prs_alloc_mem(ps, num_entries * sizeof(SRV_SHARE_INFO_0))))
+			if (!(info0 = PRS_ALLOC_MEM(ps, SRV_SHARE_INFO_0, num_entries)))
 				return False;
 			ctr->share.info0 = info0;
 		}
@@ -809,7 +809,7 @@
 		int i;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(info1 = (SRV_SHARE_INFO_1 *)prs_alloc_mem(ps, num_entries * sizeof(SRV_SHARE_INFO_1))))
+			if (!(info1 = PRS_ALLOC_MEM(ps, SRV_SHARE_INFO_1, num_entries)))
 				return False;
 			ctr->share.info1 = info1;
 		}
@@ -835,7 +835,7 @@
 		int i;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(info2 = (SRV_SHARE_INFO_2 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_2))))
+			if (!(info2 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_2,num_entries)))
 				return False;
 			ctr->share.info2 = info2;
 		}
@@ -860,8 +860,7 @@
 		int i;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(info501 = (SRV_SHARE_INFO_501 *) prs_alloc_mem(ps, num_entries *
-					sizeof (SRV_SHARE_INFO_501))))
+			if (!(info501 = PRS_ALLOC_MEM(ps, SRV_SHARE_INFO_501, num_entries)))
 				return False;
 			ctr->share.info501 = info501;
 		}
@@ -886,7 +885,7 @@
 		int i;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(info502 = (SRV_SHARE_INFO_502 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_502))))
+			if (!(info502 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_502,num_entries)))
 				return False;
 			ctr->share.info502 = info502;
 		}
@@ -912,7 +911,7 @@
 		int i;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(info1004 = (SRV_SHARE_INFO_1004 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1004))))
+			if (!(info1004 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1004,num_entries)))
 				return False;
 			ctr->share.info1004 = info1004;
 		}
@@ -938,7 +937,7 @@
 		int i;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(info1005 = (SRV_SHARE_INFO_1005 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1005))))
+			if (!(info1005 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1005,num_entries)))
 				return False;
 			ctr->share.info1005 = info1005;
 		}
@@ -958,7 +957,7 @@
 		int i;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(info1006 = (SRV_SHARE_INFO_1006 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1006))))
+			if (!(info1006 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1006,num_entries)))
 				return False;
 			ctr->share.info1006 = info1006;
 		}
@@ -978,7 +977,7 @@
 		int i;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(info1007 = (SRV_SHARE_INFO_1007 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1007))))
+			if (!(info1007 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1007,num_entries)))
 				return False;
 			ctr->share.info1007 = info1007;
 		}
@@ -1004,7 +1003,7 @@
 		int i;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(info1501 = (SRV_SHARE_INFO_1501 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1501))))
+			if (!(info1501 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1501,num_entries)))
 				return False;
 			ctr->share.info1501 = info1501;
 		}
@@ -1848,7 +1847,7 @@
 	depth++;
 
 	if(UNMARSHALLING(ps)) {
-		ctr = *pp_ctr = (SRV_SESS_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_SESS_INFO_CTR));
+		ctr = *pp_ctr = PRS_ALLOC_MEM(ps, SRV_SESS_INFO_CTR, 1);
 		if (ctr == NULL)
 			return False;
 	}
@@ -2221,7 +2220,7 @@
 	depth++;
 
 	if (UNMARSHALLING(ps)) {
-		ctr = *pp_ctr = (SRV_CONN_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_CONN_INFO_CTR));
+		ctr = *pp_ctr = PRS_ALLOC_MEM(ps, SRV_CONN_INFO_CTR, 1);
 		if (ctr == NULL)
 			return False;
 	}
@@ -2487,7 +2486,7 @@
 		int i;
 
 		if (UNMARSHALLING(ps)) {
-			if (!(info3 = (SRV_FILE_INFO_3 *)prs_alloc_mem(ps, num_entries * sizeof(SRV_FILE_INFO_3))))
+			if (!(info3 = PRS_ALLOC_MEM(ps, SRV_FILE_INFO_3, num_entries)))
 				return False;
 			ctr->file.info3 = info3;
 		}
@@ -3022,8 +3021,7 @@
 		return False;
 
 	if (UNMARSHALLING(ps)) {
-		q_n->ctr = (SRV_INFO_CTR *)
-			prs_alloc_mem(ps, sizeof(SRV_INFO_CTR));
+		q_n->ctr = PRS_ALLOC_MEM(ps, SRV_INFO_CTR, 1);
 
 		if (!q_n->ctr)
 			return False;
@@ -3310,7 +3308,7 @@
 
 		DISK_INFO *dinfo;
 
-		if(!(dinfo = (DISK_INFO *)prs_alloc_mem(ps, sizeof(*dinfo) * entries_read3)))
+		if(!(dinfo = PRS_ALLOC_MEM(ps, DISK_INFO, entries_read3)))
 		return False;
 		r_n->disk_enum_ctr.disk_info = dinfo;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_dfs_nt.c samba-3.0.9/source/rpc_server/srv_dfs_nt.c
--- samba-3.0.9-orig/source/rpc_server/srv_dfs_nt.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_dfs_nt.c	2004-12-09 09:00:27.300590719 -0600
@@ -81,9 +81,7 @@
 
 	vfs_ChDir(p->conn,p->conn->connectpath);
 
-	jn.referral_list = (struct referral*) talloc(p->mem_ctx, jn.referral_count 
-				* sizeof(struct referral));
-
+	jn.referral_list = TALLOC_ARRAY(p->mem_ctx, struct referral, jn.referral_count);
 	if(jn.referral_list == NULL) {
 		DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
 		return WERR_DFS_INTERNAL_ERROR;
@@ -245,8 +243,7 @@
 		dfs3[i].ptr_storages = 1;
      
 		/* also enumerate the storages */
-		dfs3[i].storages = (DFS_STORAGE_INFO*) talloc(ctx, j[i].referral_count * 
-						sizeof(DFS_STORAGE_INFO));
+		dfs3[i].storages = TALLOC_ARRAY(ctx, DFS_STORAGE_INFO, j[i].referral_count);
 		if (!dfs3[i].storages)
 			return False;
 
@@ -285,7 +282,7 @@
 	case 1:
 		{
 		DFS_INFO_1* dfs1;
-		dfs1 = (DFS_INFO_1*) talloc(ctx, num_jn * sizeof(DFS_INFO_1));
+		dfs1 = TALLOC_ARRAY(ctx, DFS_INFO_1, num_jn);
 		if (!dfs1)
 			return WERR_NOMEM;
 		init_reply_dfs_info_1(jn, dfs1, num_jn);
@@ -295,7 +292,7 @@
 	case 2:
 		{
 		DFS_INFO_2* dfs2;
-		dfs2 = (DFS_INFO_2*) talloc(ctx, num_jn * sizeof(DFS_INFO_2));
+		dfs2 = TALLOC_ARRAY(ctx, DFS_INFO_2, num_jn);
 		if (!dfs2)
 			return WERR_NOMEM;
 		init_reply_dfs_info_2(jn, dfs2, num_jn);
@@ -305,7 +302,7 @@
 	case 3:
 		{
 		DFS_INFO_3* dfs3;
-		dfs3 = (DFS_INFO_3*) talloc(ctx, num_jn * sizeof(DFS_INFO_3));
+		dfs3 = TALLOC_ARRAY(ctx, DFS_INFO_3, num_jn);
 		if (!dfs3)
 			return WERR_NOMEM;
 		init_reply_dfs_info_3(ctx, jn, dfs3, num_jn);
@@ -336,7 +333,7 @@
 	r_u->reshnd.ptr_hnd = 1;
 	r_u->reshnd.handle = num_jn;
   
-	r_u->ctr = (DFS_INFO_CTR*)talloc(p->mem_ctx, sizeof(DFS_INFO_CTR));
+	r_u->ctr = TALLOC_P(p->mem_ctx, DFS_INFO_CTR);
 	if (!r_u->ctr)
 		return WERR_NOMEM;
 	ZERO_STRUCTP(r_u->ctr);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_echo_nt.c samba-3.0.9/source/rpc_server/srv_echo_nt.c
--- samba-3.0.9-orig/source/rpc_server/srv_echo_nt.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_echo_nt.c	2004-12-09 09:00:27.304589726 -0600
@@ -44,7 +44,7 @@
 {
 	DEBUG(10, ("_echo_data\n"));
 
-	r_u->data = talloc(p->mem_ctx, q_u->size);
+	r_u->data = TALLOC(p->mem_ctx, q_u->size);
 	r_u->size = q_u->size;
 	memcpy(r_u->data, q_u->data, q_u->size);
 }
@@ -68,7 +68,7 @@
 
 	DEBUG(10, ("_source_data\n"));
 
-	r_u->data = talloc(p->mem_ctx, q_u->size);
+	r_u->data = TALLOC(p->mem_ctx, q_u->size);
 	r_u->size = q_u->size;
 
 	for (i = 0; i < r_u->size; i++)
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_lsa_ds_nt.c samba-3.0.9/source/rpc_server/srv_lsa_ds_nt.c
--- samba-3.0.9-orig/source/rpc_server/srv_lsa_ds_nt.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_lsa_ds_nt.c	2004-12-09 09:00:27.296591713 -0600
@@ -41,7 +41,7 @@
 
 	DEBUG(10,("fill_dsrole_dominfo_basic: enter\n"));
 
-	if ( !(basic = talloc_zero(ctx, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC))) ) {
+	if ( !(basic = TALLOC_ZERO_P(ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC)) ) {
 		DEBUG(0,("fill_dsrole_dominfo_basic: FATAL error!  talloc_xero() failed\n"));
 		return NT_STATUS_NO_MEMORY;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_lsa_hnd.c samba-3.0.9/source/rpc_server/srv_lsa_hnd.c
--- samba-3.0.9-orig/source/rpc_server/srv_lsa_hnd.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_lsa_hnd.c	2004-12-09 09:00:27.297591465 -0600
@@ -70,7 +70,7 @@
 		 * Create list.
 		 */
 
-		if ((hl = (struct handle_list *)malloc(sizeof(struct handle_list))) == NULL)
+		if ((hl = SMB_MALLOC_P(struct handle_list)) == NULL)
 			return False;
 		ZERO_STRUCTP(hl);
 
@@ -112,7 +112,7 @@
 		return False;
 	}
 
-	pol = (struct policy *)malloc(sizeof(*p));
+	pol = SMB_MALLOC_P(struct policy);
 	if (!pol) {
 		DEBUG(0,("create_policy_hnd: ERROR: out of memory!\n"));
 		return False;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_lsa_nt.c samba-3.0.9/source/rpc_server/srv_lsa_nt.c
--- samba-3.0.9-orig/source/rpc_server/srv_lsa_nt.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_lsa_nt.c	2004-12-09 09:00:27.307588981 -0600
@@ -232,14 +232,12 @@
 	/* Allocate memory for list of names */
 
 	if (num_entries > 0) {
-		if (!(trn->name = (LSA_TRANS_NAME *)talloc(ctx, sizeof(LSA_TRANS_NAME) *
-							  num_entries))) {
+		if (!(trn->name = TALLOC_ARRAY(ctx, LSA_TRANS_NAME, num_entries))) {
 			DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
 			return;
 		}
 
-		if (!(trn->uni_name = (UNISTR2 *)talloc(ctx, sizeof(UNISTR2) * 
-							num_entries))) {
+		if (!(trn->uni_name = TALLOC_ARRAY(ctx, UNISTR2, num_entries))) {
 			DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
 			return;
 		}
@@ -418,7 +416,7 @@
 
 
 	/* associate the domain SID with the (unique) handle. */
-	if ((info = (struct lsa_info *)malloc(sizeof(struct lsa_info))) == NULL)
+	if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
 		return NT_STATUS_NO_MEMORY;
 
 	ZERO_STRUCTP(info);
@@ -463,7 +461,7 @@
 	}
 
 	/* associate the domain SID with the (unique) handle. */
-	if ((info = (struct lsa_info *)malloc(sizeof(struct lsa_info))) == NULL)
+	if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
 		return NT_STATUS_NO_MEMORY;
 
 	ZERO_STRUCTP(info);
@@ -550,7 +548,7 @@
 		info->id2.auditing_enabled = 1;
 		info->id2.count1 = 7;
 		info->id2.count2 = 7;
-		if ((info->id2.auditsettings = (uint32 *)talloc(p->mem_ctx,7*sizeof(uint32))) == NULL)
+		if ((info->id2.auditsettings = TALLOC_ARRAY(p->mem_ctx,uint32, 7)) == NULL)
 			return NT_STATUS_NO_MEMORY;
 		for (i = 0; i < 7; i++)
 			info->id2.auditsettings[i] = 3;
@@ -649,8 +647,8 @@
 		DEBUG(5,("_lsa_lookup_sids: truncating SID lookup list to %d\n", num_entries));
 	}
 
-	ref = (DOM_R_REF *)talloc_zero(p->mem_ctx, sizeof(DOM_R_REF));
-	names = (LSA_TRANS_NAME_ENUM *)talloc_zero(p->mem_ctx, sizeof(LSA_TRANS_NAME_ENUM));
+	ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
+	names = TALLOC_ZERO_P(p->mem_ctx, LSA_TRANS_NAME_ENUM);
 
 	if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) {
 		r_u->status = NT_STATUS_INVALID_HANDLE;
@@ -698,8 +696,8 @@
 		DEBUG(5,("_lsa_lookup_names: truncating name lookup list to %d\n", num_entries));
 	}
 		
-	ref = (DOM_R_REF *)talloc_zero(p->mem_ctx, sizeof(DOM_R_REF));
-	rids = (DOM_RID2 *)talloc_zero(p->mem_ctx, sizeof(DOM_RID2)*num_entries);
+	ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
+	rids = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID2, num_entries);
 
 	if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) {
 		r_u->status = NT_STATUS_INVALID_HANDLE;
@@ -768,7 +766,7 @@
 	if (enum_context >= PRIV_ALL_INDEX)
 		return NT_STATUS_NO_MORE_ENTRIES;
 
-	entries = (LSA_PRIV_ENTRY *)talloc_zero(p->mem_ctx, sizeof(LSA_PRIV_ENTRY) * (PRIV_ALL_INDEX));
+	entries = TALLOC_ZERO_ARRAY(p->mem_ctx, LSA_PRIV_ENTRY, PRIV_ALL_INDEX);
 	if (entries==NULL)
 		return NT_STATUS_NO_MEMORY;
 
@@ -887,8 +885,8 @@
 	if (q_u->enum_context >= num_entries)
 		return NT_STATUS_NO_MORE_ENTRIES;
 
-	sids->ptr_sid = (uint32 *)talloc_zero(p->mem_ctx, (num_entries-q_u->enum_context)*sizeof(uint32));
-	sids->sid = (DOM_SID2 *)talloc_zero(p->mem_ctx, (num_entries-q_u->enum_context)*sizeof(DOM_SID2));
+	sids->ptr_sid = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_entries-q_u->enum_context);
+	sids->sid = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_SID2, num_entries-q_u->enum_context);
 
 	if (sids->ptr_sid==NULL || sids->sid==NULL) {
 		SAFE_FREE(map);
@@ -960,7 +958,7 @@
 		return NT_STATUS_ACCESS_DENIED;
 
 	/* associate the user/group SID with the (unique) handle. */
-	if ((info = (struct lsa_info *)malloc(sizeof(struct lsa_info))) == NULL)
+	if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
 		return NT_STATUS_NO_MEMORY;
 
 	ZERO_STRUCTP(info);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_netlog_nt.c samba-3.0.9/source/rpc_server/srv_netlog_nt.c
--- samba-3.0.9-orig/source/rpc_server/srv_netlog_nt.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_netlog_nt.c	2004-12-09 09:00:27.321585503 -0600
@@ -579,7 +579,7 @@
 	SAM_ACCOUNT *sampw;
 	struct auth_context *auth_context = NULL;
 	        
-	usr_info = (NET_USER_INFO_3 *)talloc(p->mem_ctx, sizeof(NET_USER_INFO_3));
+	usr_info = TALLOC_P(p->mem_ctx, NET_USER_INFO_3);
 	if (!usr_info)
 		return NT_STATUS_NO_MEMORY;
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_pipe.c samba-3.0.9/source/rpc_server/srv_pipe.c
--- samba-3.0.9-orig/source/rpc_server/srv_pipe.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_pipe.c	2004-12-09 09:00:27.324584758 -0600
@@ -775,7 +775,7 @@
 			int 			n_fns = 0;
 			PIPE_RPC_FNS		*context_fns;
 			
-			if ( !(context_fns = malloc(sizeof(PIPE_RPC_FNS))) ) {
+			if ( !(context_fns = SMB_MALLOC_P(PIPE_RPC_FNS)) ) {
 				DEBUG(0,("check_bind_req: malloc() failed!\n"));
 				return False;
 			}
@@ -831,8 +831,8 @@
         /* We use a temporary variable because this call can fail and 
            rpc_lookup will still be valid afterwards.  It could then succeed if
            called again later */
-        rpc_entry = realloc(rpc_lookup, 
-                            ++rpc_lookup_size*sizeof(struct rpc_table));
+	rpc_lookup_size++;
+        rpc_entry = SMB_REALLOC_ARRAY(rpc_lookup, struct rpc_table, rpc_lookup_size);
         if (NULL == rpc_entry) {
                 rpc_lookup_size--;
                 DEBUG(0, ("rpc_pipe_register_commands: memory allocation failed\n"));
@@ -843,13 +843,10 @@
         
         rpc_entry = rpc_lookup + (rpc_lookup_size - 1);
         ZERO_STRUCTP(rpc_entry);
-        rpc_entry->pipe.clnt = strdup(clnt);
-        rpc_entry->pipe.srv = strdup(srv);
-        rpc_entry->cmds = realloc(rpc_entry->cmds, 
-                                  (rpc_entry->n_cmds + size) *
-                                  sizeof(struct api_struct));
-        memcpy(rpc_entry->cmds + rpc_entry->n_cmds, cmds,
-               size * sizeof(struct api_struct));
+        rpc_entry->pipe.clnt = SMB_STRDUP(clnt);
+        rpc_entry->pipe.srv = SMB_STRDUP(srv);
+        rpc_entry->cmds = SMB_REALLOC_ARRAY(rpc_entry->cmds, struct api_struct, rpc_entry->n_cmds + size);
+        memcpy(rpc_entry->cmds + rpc_entry->n_cmds, cmds, size * sizeof(struct api_struct));
         rpc_entry->n_cmds += size;
         
         return NT_STATUS_OK;
@@ -1585,9 +1582,7 @@
 	if ((DEBUGLEVEL >= 10) && 
 	    (prs_offset(&p->in_data.data) != prs_data_size(&p->in_data.data))) {
 		size_t data_len = prs_data_size(&p->in_data.data) - prs_offset(&p->in_data.data);
-		char *data;
-
-		data = malloc(data_len);
+		char *data = SMB_MALLOC(data_len);
 
 		DEBUG(10, ("api_rpcTNP: rpc input buffer underflow (parse error?)\n"));
 		if (data) {
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_pipe_hnd.c samba-3.0.9/source/rpc_server/srv_pipe_hnd.c
--- samba-3.0.9-orig/source/rpc_server/srv_pipe_hnd.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_pipe_hnd.c	2004-12-09 09:00:27.311587987 -0600
@@ -204,8 +204,7 @@
 	for (p = Pipes; p; p = p->next)
 		DEBUG(5,("open_rpc_pipe_p: name %s pnum=%x\n", p->name, p->pnum));  
 
-	p = (smb_np_struct *)malloc(sizeof(*p));
-
+	p = SMB_MALLOC_P(smb_np_struct);
 	if (!p) {
 		DEBUG(0,("ERROR! no memory for pipes_struct!\n"));
 		return NULL;
@@ -283,10 +282,9 @@
 		return NULL;
 	}
 
-	p = (pipes_struct *)malloc(sizeof(*p));
+	p = SMB_MALLOC_P(pipes_struct);
 
-	if (!p)
-	{
+	if (!p) {
 		DEBUG(0,("ERROR! no memory for pipes_struct!\n"));
 		return NULL;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_reg_nt.c samba-3.0.9/source/rpc_server/srv_reg_nt.c
--- samba-3.0.9-orig/source/rpc_server/srv_reg_nt.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_reg_nt.c	2004-12-09 09:00:27.303589974 -0600
@@ -97,7 +97,7 @@
 	if ( subkey_len && subkeyname2[subkey_len-1] == '\\' )
 		subkeyname2[subkey_len-1] = '\0';
 
-	if ((regkey=(REGISTRY_KEY*)malloc(sizeof(REGISTRY_KEY))) == NULL)
+	if ((regkey=SMB_MALLOC_P(REGISTRY_KEY)) == NULL)
 		return NT_STATUS_NO_MEMORY;
 		
 	ZERO_STRUCTP( regkey );
@@ -373,7 +373,7 @@
 	/* couple of hard coded registry values */
 	
 	if ( strequal(name, "RefusePasswordChange") ) {
-		if ( (val = (REGISTRY_VALUE*)malloc(sizeof(REGISTRY_VALUE))) == NULL ) {
+		if ( (val = SMB_MALLOC_P(REGISTRY_VALUE)) == NULL ) {
 			DEBUG(0,("_reg_info: malloc() failed!\n"));
 			return NT_STATUS_NO_MEMORY;
 		}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_samr_nt.c samba-3.0.9/source/rpc_server/srv_samr_nt.c
--- samba-3.0.9-orig/source/rpc_server/srv_samr_nt.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_samr_nt.c	2004-12-09 09:00:27.334582274 -0600
@@ -137,7 +137,7 @@
 
 	mem_ctx = talloc_init("samr_info for domain sid %s", sid_str);
 
-	if ((info = (struct samr_info *)talloc(mem_ctx, sizeof(struct samr_info))) == NULL)
+	if ((info = TALLOC_P(mem_ctx, struct samr_info)) == NULL)
 		return NULL;
 
 	ZERO_STRUCTP(info);
@@ -255,8 +255,8 @@
 		if (info->disp_info.num_user_account % MAX_SAM_ENTRIES == 0) {
 		
 			DEBUG(10,("load_sampwd_entries: allocating more memory\n"));
-			pwd_array=(SAM_ACCOUNT *)talloc_realloc(mem_ctx, info->disp_info.disp_user_info, 
-			                  (info->disp_info.num_user_account+MAX_SAM_ENTRIES)*sizeof(SAM_ACCOUNT));
+			pwd_array=TALLOC_REALLOC_ARRAY(mem_ctx, info->disp_info.disp_user_info, SAM_ACCOUNT,
+			                  info->disp_info.num_user_account+MAX_SAM_ENTRIES);
 
 			if (pwd_array==NULL)
 				return NT_STATUS_NO_MEMORY;
@@ -322,7 +322,7 @@
 
 	info->disp_info.num_group_account=group_entries;
 
-	grp_array=(DOMAIN_GRP *)talloc(mem_ctx, info->disp_info.num_group_account*sizeof(DOMAIN_GRP));
+	grp_array=TALLOC_ARRAY(mem_ctx, DOMAIN_GRP, info->disp_info.num_group_account);
 	if (group_entries!=0 && grp_array==NULL) {
 		DEBUG(1, ("load_group_domain_entries: talloc() failed for grp_array!\n"));
 		SAFE_FREE(map);
@@ -716,9 +716,9 @@
 	if (num_entries == 0)
 		return NT_STATUS_OK;
 
-	sam = (SAM_ENTRY *)talloc_zero(ctx, sizeof(SAM_ENTRY)*num_entries);
+	sam = TALLOC_ZERO_ARRAY(ctx, SAM_ENTRY, num_entries);
 
-	uni_name = (UNISTR2 *)talloc_zero(ctx, sizeof(UNISTR2)*num_entries);
+	uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_entries);
 
 	if (sam == NULL || uni_name == NULL) {
 		DEBUG(0, ("make_user_sam_entry_list: talloc_zero failed!\n"));
@@ -871,9 +871,8 @@
 	if (num_sam_entries == 0)
 		return;
 
-	sam = (SAM_ENTRY *)talloc_zero(ctx, sizeof(SAM_ENTRY)*num_sam_entries);
-
-	uni_name = (UNISTR2 *)talloc_zero(ctx, sizeof(UNISTR2)*num_sam_entries);
+	sam = TALLOC_ZERO_ARRAY(ctx, SAM_ENTRY, num_sam_entries);
+	uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_sam_entries);
 
 	if (sam == NULL || uni_name == NULL) {
 		DEBUG(0, ("NULL pointers in SAMR_R_QUERY_DISPINFO\n"));
@@ -923,7 +922,7 @@
 		num_entries=max_entries;
 	}
 
-	*d_grp=(DOMAIN_GRP *)talloc_zero(ctx, num_entries*sizeof(DOMAIN_GRP));
+	*d_grp=TALLOC_ZERO_ARRAY(ctx, DOMAIN_GRP, num_entries);
 	if (num_entries!=0 && *d_grp==NULL){
 		SAFE_FREE(map);
 		return NT_STATUS_NO_MEMORY;
@@ -969,7 +968,7 @@
 	if (*p_num_entries == 0)
 		return NT_STATUS_OK;
 
-	*d_grp = talloc(ctx, sizeof(DOMAIN_GRP) * (*p_num_entries));
+	*d_grp = TALLOC_ARRAY(ctx, DOMAIN_GRP, *p_num_entries);
 
 	if (*d_grp == NULL) {
 		SAFE_FREE(info);
@@ -1187,7 +1186,7 @@
 		DEBUG(5, ("samr_reply_query_dispinfo: buffer size limits to only %d entries\n", max_entries));
 	}
 
-	if (!(ctr = (SAM_DISPINFO_CTR *)talloc_zero(p->mem_ctx,sizeof(SAM_DISPINFO_CTR))))
+	if (!(ctr = TALLOC_ZERO_P(p->mem_ctx,SAM_DISPINFO_CTR)))
 		return NT_STATUS_NO_MEMORY;
 
 	ZERO_STRUCTP(ctr);
@@ -1196,7 +1195,7 @@
 	switch (q_u->switch_level) {
 	case 0x1:
 		if (max_entries) {
-			if (!(ctr->sam.info1 = (SAM_DISPINFO_1 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_1))))
+			if (!(ctr->sam.info1 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_1,max_entries)))
 				return NT_STATUS_NO_MEMORY;
 		}
 		disp_ret = init_sam_dispinfo_1(p->mem_ctx, ctr->sam.info1, max_entries, enum_context, 
@@ -1206,7 +1205,7 @@
 		break;
 	case 0x2:
 		if (max_entries) {
-			if (!(ctr->sam.info2 = (SAM_DISPINFO_2 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_2))))
+			if (!(ctr->sam.info2 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_2,max_entries)))
 				return NT_STATUS_NO_MEMORY;
 		}
 		disp_ret = init_sam_dispinfo_2(p->mem_ctx, ctr->sam.info2, max_entries, enum_context, 
@@ -1216,7 +1215,7 @@
 		break;
 	case 0x3:
 		if (max_entries) {
-			if (!(ctr->sam.info3 = (SAM_DISPINFO_3 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_3))))
+			if (!(ctr->sam.info3 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_3,max_entries)))
 				return NT_STATUS_NO_MEMORY;
 		}
 		disp_ret = init_sam_dispinfo_3(p->mem_ctx, ctr->sam.info3, max_entries, enum_context, info->disp_info.disp_group_info);
@@ -1225,7 +1224,7 @@
 		break;
 	case 0x4:
 		if (max_entries) {
-			if (!(ctr->sam.info4 = (SAM_DISPINFO_4 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_4))))
+			if (!(ctr->sam.info4 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_4,max_entries)))
 				return NT_STATUS_NO_MEMORY;
 		}
 		disp_ret = init_sam_dispinfo_4(p->mem_ctx, ctr->sam.info4, max_entries, enum_context, info->disp_info.disp_user_info);
@@ -1234,7 +1233,7 @@
 		break;
 	case 0x5:
 		if (max_entries) {
-			if (!(ctr->sam.info5 = (SAM_DISPINFO_5 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_5))))
+			if (!(ctr->sam.info5 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_5,max_entries)))
 				return NT_STATUS_NO_MEMORY;
 		}
 		disp_ret = init_sam_dispinfo_5(p->mem_ctx, ctr->sam.info5, max_entries, enum_context, info->disp_info.disp_group_info);
@@ -1512,11 +1511,11 @@
 	*pp_hdr_name = NULL;
 
 	if (num_names != 0) {
-		hdr_name = (UNIHDR *)talloc_zero(ctx, sizeof(UNIHDR)*num_names);
+		hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR, num_names);
 		if (hdr_name == NULL)
 			return False;
 
-		uni_name = (UNISTR2 *)talloc_zero(ctx,sizeof(UNISTR2)*num_names);
+		uni_name = TALLOC_ZERO_ARRAY(ctx,UNISTR2, num_names);
 		if (uni_name == NULL)
 			return False;
 	}
@@ -1562,7 +1561,7 @@
 	}
 
 	if (num_rids) {
-		if ((group_attrs = (uint32 *)talloc_zero(p->mem_ctx, num_rids * sizeof(uint32))) == NULL)
+		if ((group_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids )) == NULL)
 			return NT_STATUS_NO_MEMORY;
  	}
  
@@ -1854,7 +1853,7 @@
 
 	DEBUG(5,("_samr_query_userinfo: sid:%s\n", sid_string_static(&info->sid)));
 
-	ctr = (SAM_USERINFO_CTR *)talloc_zero(p->mem_ctx, sizeof(SAM_USERINFO_CTR));
+	ctr = TALLOC_ZERO_P(p->mem_ctx, SAM_USERINFO_CTR);
 	if (!ctr)
 		return NT_STATUS_NO_MEMORY;
 
@@ -1865,7 +1864,7 @@
 
 	switch (q_u->switch_value) {
 	case 0x10:
-		ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(p->mem_ctx, sizeof(SAM_USER_INFO_10));
+		ctr->info.id10 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_10);
 		if (ctr->info.id10 == NULL)
 			return NT_STATUS_NO_MEMORY;
 
@@ -1883,11 +1882,7 @@
             expire.low = 0xffffffff;
             expire.high = 0x7fffffff;
 
-            ctr->info.id = (SAM_USER_INFO_11 *)talloc_zero(p->mem_ctx,
-                                    sizeof
-                                    (*ctr->
-                                     info.
-                                     id11));
+            ctr->info.id = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_11));
 	    ZERO_STRUCTP(ctr->info.id11);
             init_sam_user_info11(ctr->info.id11, &expire,
                          "BROOKFIELDS$",    /* name */
@@ -1900,7 +1895,7 @@
 #endif
 
 	case 0x12:
-		ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(p->mem_ctx, sizeof(SAM_USER_INFO_12));
+		ctr->info.id12 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_12);
 		if (ctr->info.id12 == NULL)
 			return NT_STATUS_NO_MEMORY;
 
@@ -1909,7 +1904,7 @@
 		break;
 		
 	case 20:
-		ctr->info.id20 = (SAM_USER_INFO_20 *)talloc_zero(p->mem_ctx,sizeof(SAM_USER_INFO_20));
+		ctr->info.id20 = TALLOC_ZERO_P(p->mem_ctx,SAM_USER_INFO_20);
 		if (ctr->info.id20 == NULL)
 			return NT_STATUS_NO_MEMORY;
 		if (!NT_STATUS_IS_OK(r_u->status = get_user_info_20(p->mem_ctx, ctr->info.id20, &info->sid)))
@@ -1917,7 +1912,7 @@
 		break;
 
 	case 21:
-		ctr->info.id21 = (SAM_USER_INFO_21 *)talloc_zero(p->mem_ctx,sizeof(SAM_USER_INFO_21));
+		ctr->info.id21 = TALLOC_ZERO_P(p->mem_ctx,SAM_USER_INFO_21);
 		if (ctr->info.id21 == NULL)
 			return NT_STATUS_NO_MEMORY;
 		if (!NT_STATUS_IS_OK(r_u->status = get_user_info_21(p->mem_ctx, ctr->info.id21, 
@@ -2025,7 +2020,7 @@
 
 	uint32 num_users=0, num_groups=0, num_aliases=0;
 
-	if ((ctr = (SAM_UNK_CTR *)talloc_zero(p->mem_ctx, sizeof(SAM_UNK_CTR))) == NULL)
+	if ((ctr = TALLOC_ZERO_P(p->mem_ctx, SAM_UNK_CTR)) == NULL)
 		return NT_STATUS_NO_MEMORY;
 
 	ZERO_STRUCTP(ctr);
@@ -2510,8 +2505,8 @@
 	if (num_sam_entries == 0)
 		return True;
 
-	sam = (SAM_ENTRY *)talloc_zero(ctx, sizeof(SAM_ENTRY)*num_sam_entries);
-	uni_name = (UNISTR2 *)talloc_zero(ctx, sizeof(UNISTR2)*num_sam_entries);
+	sam = TALLOC_ZERO_ARRAY(ctx, SAM_ENTRY, num_sam_entries);
+	uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_sam_entries);
 
 	if (sam == NULL || uni_name == NULL)
 		return False;
@@ -3185,7 +3180,7 @@
 			continue;
 		}
 
-		new_rids=(uint32 *)talloc_realloc(p->mem_ctx, rids, (num_groups+tmp_num_groups)*sizeof(uint32));
+		new_rids=TALLOC_REALLOC_ARRAY(p->mem_ctx, rids, uint32, num_groups+tmp_num_groups);
 		if (new_rids==NULL) {
 			DEBUG(0,("_samr_query_useraliases: could not realloc memory\n"));
 			return NT_STATUS_NO_MEMORY;
@@ -3234,7 +3229,7 @@
 	if (!pdb_enum_aliasmem(&alias_sid, &sids, &num_sids))
 		return NT_STATUS_NO_SUCH_ALIAS;
 
-	sid = (DOM_SID2 *)talloc_zero(p->mem_ctx, sizeof(DOM_SID2) * num_sids);	
+	sid = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_SID2, num_sids);	
 	if (num_sids!=0 && sid == NULL) {
 		SAFE_FREE(sids);
 		return NT_STATUS_NO_MEMORY;
@@ -3260,7 +3255,7 @@
 			return;
 	}
 	
-	*uids = Realloc(*uids, (*num+1) * sizeof(uid_t));
+	*uids = SMB_REALLOC_ARRAY(*uids, uid_t, *num+1);
 
 	if (*uids == NULL)
 		return;
@@ -3357,8 +3352,8 @@
 	if(!get_memberuids(gid, &uids, &num))
 		return NT_STATUS_NO_SUCH_GROUP;
 
-	rid=talloc_zero(p->mem_ctx, sizeof(uint32)*num);
-	attr=talloc_zero(p->mem_ctx, sizeof(uint32)*num);
+	rid=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num);
+	attr=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num);
 	
 	if (num!=0 && (rid==NULL || attr==NULL))
 		return NT_STATUS_NO_MEMORY;
@@ -3948,7 +3943,7 @@
 	if (!ret)
 		return NT_STATUS_INVALID_HANDLE;
 
-	ctr=(GROUP_INFO_CTR *)talloc_zero(p->mem_ctx, sizeof(GROUP_INFO_CTR));
+	ctr=TALLOC_ZERO_P(p->mem_ctx, GROUP_INFO_CTR);
 	if (ctr==NULL)
 		return NT_STATUS_NO_MEMORY;
 
@@ -4279,7 +4274,7 @@
 
 	uint32 account_policy_temp;
 
-	if ((ctr = (SAM_UNK_CTR *)talloc_zero(p->mem_ctx, sizeof(SAM_UNK_CTR))) == NULL)
+	if ((ctr = TALLOC_ZERO_P(p->mem_ctx, SAM_UNK_CTR)) == NULL)
 		return NT_STATUS_NO_MEMORY;
 
 	ZERO_STRUCTP(ctr);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_spoolss_nt.c samba-3.0.9/source/rpc_server/srv_spoolss_nt.c
--- samba-3.0.9-orig/source/rpc_server/srv_spoolss_nt.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_spoolss_nt.c	2004-12-09 09:00:27.349578549 -0600
@@ -238,7 +238,7 @@
 	if (!sp)
 		return NULL;
 
-	new_sp = (SPOOL_NOTIFY_OPTION *)malloc(sizeof(SPOOL_NOTIFY_OPTION));
+	new_sp = SMB_MALLOC_P(SPOOL_NOTIFY_OPTION);
 	if (!new_sp)
 		return NULL;
 
@@ -595,7 +595,7 @@
 
 	DEBUG(10,("open_printer_hnd: name [%s]\n", name));
 
-	if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL)
+	if((new_printer=SMB_MALLOC_P(Printer_entry)) == NULL)
 		return False;
 
 	ZERO_STRUCTP(new_printer);
@@ -743,7 +743,7 @@
 	init_unistr2(&unistr, msg->notify.data, UNI_STR_TERMINATE);
 
 	data->notify_data.data.length = msg->len * 2;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, msg->len * 2);
+	data->notify_data.data.string = TALLOC_ARRAY(mem_ctx, uint16, msg->len);
 
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -780,7 +780,7 @@
 		return;
 
 	data->notify_data.data.length = prs_offset(&ps);
-	data->notify_data.data.string = talloc(mem_ctx, prs_offset(&ps));
+	data->notify_data.data.string = TALLOC(mem_ctx, prs_offset(&ps));
 
 	prs_copy_all_data_out((char *)data->notify_data.data.string, &ps);
 
@@ -938,7 +938,7 @@
 	if ( i == ctr->num_groups ) {
 		ctr->num_groups++;
 
-		if ( !(groups = talloc_realloc( ctr->ctx, ctr->msg_groups, sizeof(SPOOLSS_NOTIFY_MSG_GROUP)*ctr->num_groups)) ) {
+		if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
 			DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
 			return 0;
 		}
@@ -956,7 +956,7 @@
 	
 	msg_grp->num_msgs++;
 	
-	if ( !(msg_list =  talloc_realloc( ctr->ctx, msg_grp->msgs, sizeof(SPOOLSS_NOTIFY_MSG)*msg_grp->num_msgs )) ) {
+	if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
 		DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
 		return 0;
 	}
@@ -968,7 +968,7 @@
 	/* need to allocate own copy of data */
 	
 	if ( msg->len != 0 ) 
-		msg_grp->msgs[new_slot].notify.data = talloc_memdup( ctr->ctx, msg->notify.data, msg->len );
+		msg_grp->msgs[new_slot].notify.data = TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
 	
 	return ctr->num_groups;
 }
@@ -1026,7 +1026,7 @@
 		
 		/* allocate the max entries possible */
 		
-		data = talloc( mem_ctx, msg_group->num_msgs*sizeof(SPOOL_NOTIFY_INFO_DATA) );
+		data = TALLOC_ARRAY( mem_ctx, SPOOL_NOTIFY_INFO_DATA, msg_group->num_msgs);
 		ZERO_STRUCTP(data);
 		
 		/* build the array of change notifications */
@@ -1446,7 +1446,7 @@
 	
 	/* bulk copy first */
 	
-	d = talloc_memdup(ctx, devmode, sizeof(DEVICEMODE));
+	d = TALLOC_MEMDUP(ctx, devmode, sizeof(DEVICEMODE));
 	if (!d)
 		return NULL;
 		
@@ -1454,7 +1454,7 @@
 	
 	len = unistrlen(devmode->devicename.buffer);
 	if (len != -1) {
-		d->devicename.buffer = talloc(ctx, len*2);
+		d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len);
 		if (unistrcpy(d->devicename.buffer, devmode->devicename.buffer) != len)
 			return NULL;
 	}
@@ -1462,12 +1462,12 @@
 
 	len = unistrlen(devmode->formname.buffer);
 	if (len != -1) {
-		d->devicename.buffer = talloc(ctx, len*2);
+		d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len);
 		if (unistrcpy(d->formname.buffer, devmode->formname.buffer) != len)
 			return NULL;
 	}
 
-	d->private = talloc_memdup(ctx, devmode->private, devmode->driverextra);
+	d->private = TALLOC_MEMDUP(ctx, devmode->private, devmode->driverextra);
 	
 	return d;
 }
@@ -1904,7 +1904,7 @@
 	if ((devmode->driverextra != 0) && (devmode->private != NULL)) {
 		SAFE_FREE(nt_devmode->private);
 		nt_devmode->driverextra=devmode->driverextra;
-		if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL)
+		if((nt_devmode->private=SMB_MALLOC_ARRAY(uint8, nt_devmode->driverextra)) == NULL)
 			return False;
 		memcpy(nt_devmode->private, devmode->private, nt_devmode->driverextra);
 	}
@@ -2245,11 +2245,11 @@
 		
 		/* special case for 0 length values */
 		if ( data_len ) {
-			if ( (*data  = (uint8 *)talloc_memdup(ctx, regval_data_p(val), data_len)) == NULL )
+			if ( (*data  = (uint8 *)TALLOC_MEMDUP(ctx, regval_data_p(val), data_len)) == NULL )
 				return WERR_NOMEM;
 		}
 		else {
-			if ( (*data  = (uint8 *)talloc_zero(ctx, in_size)) == NULL )
+			if ( (*data  = (uint8 *)TALLOC_ZERO(ctx, in_size)) == NULL )
 				return WERR_NOMEM;
 		}
 	}
@@ -2296,7 +2296,7 @@
 		
 	if (!StrCaseCmp(value, "W3SvcInstalled")) {
 		*type = 0x4;
-		if((*data = (uint8 *)talloc_zero(ctx, 4*sizeof(uint8) )) == NULL)
+		if((*data = (uint8 *)TALLOC_ZERO(ctx, 4*sizeof(uint8) )) == NULL)
 			return WERR_NOMEM;
 		*needed = 0x4;
 		return WERR_OK;
@@ -2304,7 +2304,7 @@
 
 	if (!StrCaseCmp(value, "BeepEnabled")) {
 		*type = 0x4;
-		if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+		if((*data = (uint8 *)TALLOC(ctx, 4*sizeof(uint8) )) == NULL)
 			return WERR_NOMEM;
 		SIVAL(*data, 0, 0x00);
 		*needed = 0x4;			
@@ -2313,7 +2313,7 @@
 
 	if (!StrCaseCmp(value, "EventLog")) {
 		*type = 0x4;
-		if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+		if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL)
 			return WERR_NOMEM;
 		/* formally was 0x1b */
 		SIVAL(*data, 0, 0x0);
@@ -2323,7 +2323,7 @@
 
 	if (!StrCaseCmp(value, "NetPopup")) {
 		*type = 0x4;
-		if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+		if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL)
 			return WERR_NOMEM;
 		SIVAL(*data, 0, 0x00);
 		*needed = 0x4;
@@ -2332,7 +2332,7 @@
 
 	if (!StrCaseCmp(value, "MajorVersion")) {
 		*type = 0x4;
-		if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+		if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL)
 			return WERR_NOMEM;
 
 		/* Windows NT 4.0 seems to not allow uploading of drivers
@@ -2351,7 +2351,7 @@
 
 	if (!StrCaseCmp(value, "MinorVersion")) {
 		*type = 0x4;
-		if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+		if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL)
 			return WERR_NOMEM;
 		SIVAL(*data, 0, 0);
 		*needed = 0x4;
@@ -2369,7 +2369,7 @@
 		*type = 0x3;
 		*needed = 0x114;
 
-		if((*data = (uint8 *)talloc(ctx, (*needed)*sizeof(uint8) )) == NULL)
+		if((*data = (uint8 *)TALLOC(ctx, *needed)) == NULL)
 			return WERR_NOMEM;
 		ZERO_STRUCTP( *data );
 		
@@ -2388,7 +2388,7 @@
 		const char *string="C:\\PRINTERS";
 		*type = 0x1;			
 		*needed = 2*(strlen(string)+1);		
-		if((*data  = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
+		if((*data  = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
 			return WERR_NOMEM;
 		memset(*data, 0, (*needed > in_size) ? *needed:in_size);
 		
@@ -2404,7 +2404,7 @@
 		const char *string="Windows NT x86";
 		*type = 0x1;			
 		*needed = 2*(strlen(string)+1);	
-		if((*data  = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
+		if((*data  = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
 			return WERR_NOMEM;
 		memset(*data, 0, (*needed > in_size) ? *needed:in_size);
 		for (i=0; i<strlen(string); i++) {
@@ -2416,7 +2416,7 @@
 
 	if (!StrCaseCmp(value, "DsPresent")) {
 		*type = 0x4;
-		if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+		if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL)
 			return WERR_NOMEM;
 		SIVAL(*data, 0, 0x01);
 		*needed = 0x4;
@@ -2430,7 +2430,7 @@
 			return WERR_BADFILE;
 		*type = 0x1;			
 		*needed = 2*(strlen(hostname)+1);	
-		if((*data  = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
+		if((*data  = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
 			return WERR_NOMEM;
 		memset(*data, 0, (*needed > in_size) ? *needed:in_size);
 		for (i=0; i<strlen(hostname); i++) {
@@ -2505,7 +2505,7 @@
 		if ( strequal(value, "ChangeId") ) {
 			*type = REG_DWORD;
 			*needed = sizeof(uint32);
-			if ( (*data = (uint8*)talloc(p->mem_ctx, sizeof(uint32))) == NULL) {
+			if ( (*data = (uint8*)TALLOC(p->mem_ctx, sizeof(uint32))) == NULL) {
 				status = WERR_NOMEM;
 				goto done;
 			}
@@ -2527,7 +2527,7 @@
 		/* reply this param doesn't exist */
 		
 		if ( *out_size ) {
-			if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) {
+			if((*data=(uint8 *)TALLOC_ZERO_ARRAY(p->mem_ctx, uint8, *out_size)) == NULL) {
 				if ( printer ) 
 					free_a_printer( &printer, 2 );
 				return WERR_NOMEM;
@@ -2774,7 +2774,7 @@
 	len = rpcstr_push(temp, printer->info_2->servername, sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -2809,7 +2809,7 @@
 	len = rpcstr_push(temp, p, sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -2835,7 +2835,7 @@
 	len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -2863,7 +2863,7 @@
 	len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -2890,7 +2890,7 @@
 	len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -2919,7 +2919,7 @@
 		len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -2946,7 +2946,7 @@
 	len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -2985,7 +2985,7 @@
 	len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -3012,7 +3012,7 @@
 	len = rpcstr_push(temp,  printer->info_2->printprocessor, sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -3039,7 +3039,7 @@
 	len = rpcstr_push(temp,  printer->info_2->parameters, sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -3066,7 +3066,7 @@
 	len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -3226,7 +3226,7 @@
 	len = rpcstr_push(temp, queue->fs_user, sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -3266,7 +3266,7 @@
 	len = rpcstr_push(temp, queue->fs_file, sizeof(temp)-2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -3316,7 +3316,7 @@
 	len = rpcstr_push(temp, p, sizeof(temp) - 2, STR_TERMINATE);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 	
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -3414,7 +3414,7 @@
 	len = sizeof(SYSTEMTIME);
 
 	data->notify_data.data.length = len;
-	data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+	data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
 
 	if (!data->notify_data.data.string) {
 		data->notify_data.data.length = 0;
@@ -3636,7 +3636,7 @@
 		if (!search_notify(type, field, &j) )
 			continue;
 
-		if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
+		if((tid=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) {
 			DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
 			return False;
 		} else 
@@ -3692,7 +3692,7 @@
 		if (!search_notify(type, field, &j) )
 			continue;
 
-		if((tid=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
+		if((tid=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) {
 			DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
 			return False;
 		}
@@ -3976,7 +3976,7 @@
 
 	/* it's the first time, add it to the list */
 	if (session_counter==NULL) {
-		if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL) {
+		if((session_counter=SMB_MALLOC_P(counter_printer_0)) == NULL) {
 			free_a_printer(&ntprinter, 2);
 			return False;
 		}
@@ -4170,7 +4170,7 @@
 		goto done;
 	}
 
-	if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) {
+	if ((devmode = SMB_MALLOC_P(DEVICEMODE)) == NULL) {
 		DEBUG(2,("construct_dev_mode: malloc fail.\n"));
 		goto done;
 	}
@@ -4267,7 +4267,7 @@
 		return False;
 
 	*pp_printer = NULL;
-	if ((printer = (PRINTER_INFO_3 *)malloc(sizeof(PRINTER_INFO_3))) == NULL) {
+	if ((printer = SMB_MALLOC_P(PRINTER_INFO_3)) == NULL) {
 		DEBUG(2,("construct_printer_info_3: malloc fail.\n"));
 		return False;
 	}
@@ -4396,7 +4396,7 @@
 			DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
 
 			if (construct_printer_info_1(NULL, flags, &current_prt, snum)) {
-				if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) {
+				if((tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_1, *returned +1)) == NULL) {
 					DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n"));
 					SAFE_FREE(printers);
 					*returned=0;
@@ -4485,7 +4485,7 @@
 	 * undocumented RPC call.
 	 */
 	
-	if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL)
+	if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL)
 		return WERR_NOMEM;
 
 	*returned=1;
@@ -4569,7 +4569,7 @@
 			DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
 				
 			if (construct_printer_info_2(NULL, &current_prt, snum)) {
-				if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) {
+				if((tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, *returned +1)) == NULL) {
 					DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n"));
 					SAFE_FREE(printers);
 					*returned = 0;
@@ -4745,7 +4745,7 @@
 {
 	PRINTER_INFO_0 *printer=NULL;
 
-	if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL)
+	if((printer=SMB_MALLOC_P(PRINTER_INFO_0)) == NULL)
 		return WERR_NOMEM;
 
 	construct_printer_info_0(print_hnd, printer, snum);
@@ -4778,7 +4778,7 @@
 {
 	PRINTER_INFO_1 *printer=NULL;
 
-	if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL)
+	if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL)
 		return WERR_NOMEM;
 
 	construct_printer_info_1(print_hnd, PRINTER_ENUM_ICON8, printer, snum);
@@ -4811,7 +4811,7 @@
 {
 	PRINTER_INFO_2 *printer=NULL;
 
-	if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL)
+	if((printer=SMB_MALLOC_P(PRINTER_INFO_2))==NULL)
 		return WERR_NOMEM;
 	
 	construct_printer_info_2(print_hnd, printer, snum);
@@ -4878,7 +4878,7 @@
 {
 	PRINTER_INFO_4 *printer=NULL;
 
-	if((printer=(PRINTER_INFO_4*)malloc(sizeof(PRINTER_INFO_4)))==NULL)
+	if((printer=SMB_MALLOC_P(PRINTER_INFO_4))==NULL)
 		return WERR_NOMEM;
 
 	if (!construct_printer_info_4(print_hnd, printer, snum))
@@ -4912,7 +4912,7 @@
 {
 	PRINTER_INFO_5 *printer=NULL;
 
-	if((printer=(PRINTER_INFO_5*)malloc(sizeof(PRINTER_INFO_5)))==NULL)
+	if((printer=SMB_MALLOC_P(PRINTER_INFO_5))==NULL)
 		return WERR_NOMEM;
 
 	if (!construct_printer_info_5(print_hnd, printer, snum))
@@ -4943,7 +4943,7 @@
 {
 	PRINTER_INFO_7 *printer=NULL;
 
-	if((printer=(PRINTER_INFO_7*)malloc(sizeof(PRINTER_INFO_7)))==NULL)
+	if((printer=SMB_MALLOC_P(PRINTER_INFO_7))==NULL)
 		return WERR_NOMEM;
 
 	if (!construct_printer_info_7(print_hnd, printer, snum))
@@ -5145,7 +5145,7 @@
 
 		/* add one extra unit16 for the second terminating NULL */
 		
-		if ( (tuary=Realloc(*uni_array, (j+1+strlen(line)+2)*sizeof(uint16))) == NULL ) {
+		if ( (tuary=SMB_REALLOC_ARRAY(*uni_array, uint16, j+1+strlen(line)+2)) == NULL ) {
 			DEBUG(2,("init_unistr_array: Realloc error\n" ));
 			return 0;
 		} else
@@ -5421,7 +5421,7 @@
 	DRIVER_INFO_1 *info=NULL;
 	WERROR status;
 	
-	if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL)
+	if((info=SMB_MALLOC_P(DRIVER_INFO_1)) == NULL)
 		return WERR_NOMEM;
 	
 	status=construct_printer_driver_info_1(info, snum, servername, architecture, version);
@@ -5458,7 +5458,7 @@
 	DRIVER_INFO_2 *info=NULL;
 	WERROR status;
 	
-	if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL)
+	if((info=SMB_MALLOC_P(DRIVER_INFO_2)) == NULL)
 		return WERR_NOMEM;
 	
 	status=construct_printer_driver_info_2(info, snum, servername, architecture, version);
@@ -6444,7 +6444,7 @@
 	JOB_INFO_1 *info;
 	int i;
 	
-	info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1));
+	info=SMB_MALLOC_ARRAY(JOB_INFO_1,*returned);
 	if (info==NULL) {
 		SAFE_FREE(queue);
 		*returned=0;
@@ -6494,7 +6494,7 @@
 	WERROR result;
 	DEVICEMODE *devmode = NULL;
 	
-	info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2));
+	info=SMB_MALLOC_ARRAY(JOB_INFO_2,*returned);
 	if (info==NULL) {
 		*returned=0;
 		result = WERR_NOMEM;
@@ -6686,7 +6686,7 @@
 			return WERR_NOMEM;
 
 		if(ndrivers != 0) {
-			if((tdi1=(DRIVER_INFO_1 *)Realloc(driver_info_1, (*returned+ndrivers) * sizeof(DRIVER_INFO_1))) == NULL) {
+			if((tdi1=SMB_REALLOC_ARRAY(driver_info_1, DRIVER_INFO_1, *returned+ndrivers )) == NULL) {
 				DEBUG(0,("enumprinterdrivers_level1: failed to enlarge driver info buffer!\n"));
 				SAFE_FREE(driver_info_1);
 				SAFE_FREE(list);
@@ -6765,7 +6765,7 @@
 			return WERR_NOMEM;
 
 		if(ndrivers != 0) {
-			if((tdi2=(DRIVER_INFO_2 *)Realloc(driver_info_2, (*returned+ndrivers) * sizeof(DRIVER_INFO_2))) == NULL) {
+			if((tdi2=SMB_REALLOC_ARRAY(driver_info_2, DRIVER_INFO_2, *returned+ndrivers )) == NULL) {
 				DEBUG(0,("enumprinterdrivers_level2: failed to enlarge driver info buffer!\n"));
 				SAFE_FREE(driver_info_2);
 				SAFE_FREE(list);
@@ -6845,7 +6845,7 @@
 			return WERR_NOMEM;
 
 		if(ndrivers != 0) {
-			if((tdi3=(DRIVER_INFO_3 *)Realloc(driver_info_3, (*returned+ndrivers) * sizeof(DRIVER_INFO_3))) == NULL) {
+			if((tdi3=SMB_REALLOC_ARRAY(driver_info_3, DRIVER_INFO_3, *returned+ndrivers )) == NULL) {
 				DEBUG(0,("enumprinterdrivers_level3: failed to enlarge driver info buffer!\n"));
 				SAFE_FREE(driver_info_3);
 				SAFE_FREE(list);
@@ -6998,7 +6998,7 @@
 
 	switch (level) {
 	case 1:
-		if ((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) {
+		if ((forms_1=SMB_MALLOC_ARRAY(FORM_1, *numofforms)) == NULL) {
 			*numofforms=0;
 			return WERR_NOMEM;
 		}
@@ -7202,7 +7202,7 @@
 		close(fd);
 
 		if(numlines) {
-			if((ports=(PORT_INFO_1 *)malloc( numlines * sizeof(PORT_INFO_1) )) == NULL) {
+			if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) {
 				DEBUG(10,("Returning WERR_NOMEM [%s]\n", 
 					  dos_errstr(WERR_NOMEM)));
 				file_lines_free(qlines);
@@ -7222,7 +7222,7 @@
 	} else {
 		*returned = 1; /* Sole Samba port returned. */
 
-		if((ports=(PORT_INFO_1 *)malloc( sizeof(PORT_INFO_1) )) == NULL)
+		if((ports=SMB_MALLOC_P(PORT_INFO_1)) == NULL)
 			return WERR_NOMEM;
 	
 		DEBUG(10,("enumports_level_1: port name %s\n", SAMBA_PRINTER_PORT_NAME));
@@ -7301,7 +7301,7 @@
 		close(fd);
 
 		if(numlines) {
-			if((ports=(PORT_INFO_2 *)malloc( numlines * sizeof(PORT_INFO_2) )) == NULL) {
+			if((ports=SMB_MALLOC_ARRAY( PORT_INFO_2, numlines)) == NULL) {
 				file_lines_free(qlines);
 				return WERR_NOMEM;
 			}
@@ -7320,7 +7320,7 @@
 
 		*returned = 1;
 
-		if((ports=(PORT_INFO_2 *)malloc( sizeof(PORT_INFO_2) )) == NULL)
+		if((ports=SMB_MALLOC_P(PORT_INFO_2)) == NULL)
 			return WERR_NOMEM;
 	
 		DEBUG(10,("enumports_level_2: port name %s\n", SAMBA_PRINTER_PORT_NAME));
@@ -7400,7 +7400,7 @@
 	int	snum;
 	WERROR err = WERR_OK;
 
-	if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) {
+	if ((printer = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL)) == NULL) {
 		DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
 		return WERR_NOMEM;
 	}
@@ -7729,7 +7729,7 @@
 	if (!(short_archi = get_short_archi(long_archi)))
 		return WERR_INVALID_ENVIRONMENT;
 
-	if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL)
+	if((info=SMB_MALLOC_P(DRIVER_DIRECTORY_1)) == NULL)
 		return WERR_NOMEM;
 
 	slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", pservername, short_archi);
@@ -7897,7 +7897,7 @@
 
 		*out_max_value_len=(in_value_len/sizeof(uint16));
 		
-		if((*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL)
+		if((*out_value=(uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL)
 		{
 			result = WERR_NOMEM;
 			goto done;
@@ -7912,7 +7912,7 @@
 		
 		/* only allocate when given a non-zero data_len */
 		
-		if ( in_data_len && ((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) )
+		if ( in_data_len && ((*data_out=(uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) )
 		{
 			result = WERR_NOMEM;
 			goto done;
@@ -7933,7 +7933,7 @@
 	
 		/* name */
 		*out_max_value_len=(in_value_len/sizeof(uint16));
-		if ( (*out_value = (uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) 
+		if ( (*out_value = (uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) 
 		{
 			result = WERR_NOMEM;
 			goto done;
@@ -7948,7 +7948,7 @@
 		/* data - counted in bytes */
 
 		*out_max_data_len = in_data_len;
-		if ( (*data_out = (uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) 
+		if ( (*data_out = (uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) 
 		{
 			result = WERR_NOMEM;
 			goto done;
@@ -8333,7 +8333,7 @@
 {
 	PRINTPROCESSOR_1 *info_1=NULL;
 	
-	if((info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1))) == NULL)
+	if((info_1 = SMB_MALLOC_P(PRINTPROCESSOR_1)) == NULL)
 		return WERR_NOMEM;
 
 	(*returned) = 0x1;
@@ -8400,7 +8400,7 @@
 {
 	PRINTPROCDATATYPE_1 *info_1=NULL;
 	
-	if((info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1))) == NULL)
+	if((info_1 = SMB_MALLOC_P(PRINTPROCDATATYPE_1)) == NULL)
 		return WERR_NOMEM;
 
 	(*returned) = 0x1;
@@ -8460,7 +8460,7 @@
 {
 	PRINTMONITOR_1 *info_1=NULL;
 	
-	if((info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1))) == NULL)
+	if((info_1 = SMB_MALLOC_P(PRINTMONITOR_1)) == NULL)
 		return WERR_NOMEM;
 
 	(*returned) = 0x1;
@@ -8492,7 +8492,7 @@
 {
 	PRINTMONITOR_2 *info_2=NULL;
 	
-	if((info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2))) == NULL)
+	if((info_2 = SMB_MALLOC_P(PRINTMONITOR_2)) == NULL)
 		return WERR_NOMEM;
 
 	(*returned) = 0x1;
@@ -8567,7 +8567,7 @@
 	BOOL found=False;
 	JOB_INFO_1 *info_1=NULL;
 
-	info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
+	info_1=SMB_MALLOC_P(JOB_INFO_1);
 
 	if (info_1 == NULL) {
 		return WERR_NOMEM;
@@ -8618,7 +8618,7 @@
 	DEVICEMODE 	*devmode = NULL;
 	NT_DEVICEMODE	*nt_devmode = NULL;
 
-	info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
+	info_2=SMB_MALLOC_P(JOB_INFO_2);
 
 	ZERO_STRUCTP(info_2);
 
@@ -8650,7 +8650,7 @@
 	if ( !(nt_devmode=print_job_devmode( lp_const_servicename(snum), jobid )) )
 		devmode = construct_dev_mode(snum);
 	else {
-		if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) != NULL) {
+		if ((devmode = SMB_MALLOC_P(DEVICEMODE)) != NULL) {
 			ZERO_STRUCTP( devmode );
 			convert_nt_devicemode( devmode, nt_devmode );
 		}
@@ -8828,7 +8828,7 @@
 		
 		if ( *out_size ) 
 		{
-			if( (*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL ) {
+			if( (*data=(uint8 *)TALLOC_ZERO(p->mem_ctx, *out_size*sizeof(uint8))) == NULL ) {
 				status = WERR_NOMEM;
 				goto done;
 			}
@@ -9187,7 +9187,7 @@
 	num_entries = regval_ctr_numvals( &p_data->keys[key_index].values );
 	if ( num_entries )
 	{
-		if ( (enum_values=talloc(p->mem_ctx, num_entries*sizeof(PRINTER_ENUM_VALUES))) == NULL )
+		if ( (enum_values=TALLOC_ARRAY(p->mem_ctx, PRINTER_ENUM_VALUES, num_entries)) == NULL )
 		{
 			DEBUG(0,("_spoolss_enumprinterdataex: talloc() failed to allocate memory for [%lu] bytes!\n",
 				(unsigned long)num_entries*sizeof(PRINTER_ENUM_VALUES)));
@@ -9219,7 +9219,7 @@
 		
 		data_len = regval_size( val );
 		if ( data_len ) {
-			if ( !(enum_values[i].data = talloc_memdup(p->mem_ctx, regval_data_p(val), data_len)) ) 
+			if ( !(enum_values[i].data = TALLOC_MEMDUP(p->mem_ctx, regval_data_p(val), data_len)) ) 
 			{
 				DEBUG(0,("talloc_memdup failed to allocate memory [data_len=%d] for data!\n", 
 					data_len ));
@@ -9282,7 +9282,7 @@
 	if (!get_short_archi(long_archi))
 		return WERR_INVALID_ENVIRONMENT;
 
-	if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL)
+	if((info=SMB_MALLOC_P(PRINTPROCESSOR_DIRECTORY_1)) == NULL)
 		return WERR_NOMEM;
 
 	pstrcpy(path, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86");
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_srvsvc_nt.c samba-3.0.9/source/rpc_server/srv_srvsvc_nt.c
--- samba-3.0.9-orig/source/rpc_server/srv_srvsvc_nt.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_srvsvc_nt.c	2004-12-09 09:00:27.315586994 -0600
@@ -527,10 +527,12 @@
 	switch (info_level) {
 	case 0:
 	{
-		SRV_SHARE_INFO_0 *info0;
+		SRV_SHARE_INFO_0 *info0 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_0, num_entries);
 		int i = 0;
 
-		info0 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_0));
+		if (!info0) {
+			return False;
+		}
 
 		for (snum = *resume_hnd; snum < num_services; snum++) {
 			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
@@ -545,10 +547,12 @@
 
 	case 1:
 	{
-		SRV_SHARE_INFO_1 *info1;
+		SRV_SHARE_INFO_1 *info1 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1, num_entries);
 		int i = 0;
 
-		info1 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1));
+		if (!info1) {
+			return False;
+		}
 
 		for (snum = *resume_hnd; snum < num_services; snum++) {
 			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
@@ -562,10 +566,12 @@
 
 	case 2:
 	{
-		SRV_SHARE_INFO_2 *info2;
+		SRV_SHARE_INFO_2 *info2 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_2, num_entries);
 		int i = 0;
 
-		info2 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_2));
+		if (!info2) {
+			return False;
+		}
 
 		for (snum = *resume_hnd; snum < num_services; snum++) {
 			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
@@ -579,10 +585,12 @@
 
 	case 501:
 	{
-		SRV_SHARE_INFO_501 *info501;
+		SRV_SHARE_INFO_501 *info501 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_501, num_entries);
 		int i = 0;
 	
-		info501 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_501));
+		if (!info501) {
+			return False;
+		}
 
 		for (snum = *resume_hnd; snum < num_services; snum++) {
 			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
@@ -596,10 +604,12 @@
 
 	case 502:
 	{
-		SRV_SHARE_INFO_502 *info502;
+		SRV_SHARE_INFO_502 *info502 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_502, num_entries);
 		int i = 0;
 
-		info502 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_502));
+		if (!info502) {
+			return False;
+		}
 
 		for (snum = *resume_hnd; snum < num_services; snum++) {
 			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
@@ -615,10 +625,12 @@
 	
 	case 1004:
 	{
-		SRV_SHARE_INFO_1004 *info1004;
+		SRV_SHARE_INFO_1004 *info1004 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1004, num_entries);
 		int i = 0;
 
-		info1004 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1004));
+		if (!info1004) {
+			return False;
+		}
 
 		for (snum = *resume_hnd; snum < num_services; snum++) {
 			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
@@ -632,10 +644,12 @@
 
 	case 1005:
 	{
-		SRV_SHARE_INFO_1005 *info1005;
+		SRV_SHARE_INFO_1005 *info1005 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1005, num_entries);
 		int i = 0;
 
-		info1005 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1005));
+		if (!info1005) {
+			return False;
+		}
 
 		for (snum = *resume_hnd; snum < num_services; snum++) {
 			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
@@ -649,10 +663,12 @@
 
 	case 1006:
 	{
-		SRV_SHARE_INFO_1006 *info1006;
+		SRV_SHARE_INFO_1006 *info1006 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1006, num_entries);
 		int i = 0;
 
-		info1006 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1006));
+		if (!info1006) {
+			return False;
+		}
 
 		for (snum = *resume_hnd; snum < num_services; snum++) {
 			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
@@ -666,10 +682,12 @@
 
 	case 1007:
 	{
-		SRV_SHARE_INFO_1007 *info1007;
+		SRV_SHARE_INFO_1007 *info1007 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1007, num_entries);
 		int i = 0;
 
-		info1007 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1007));
+		if (!info1007) {
+			return False;
+		}
 
 		for (snum = *resume_hnd; snum < num_services; snum++) {
 			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
@@ -683,10 +701,12 @@
 
 	case 1501:
 	{
-		SRV_SHARE_INFO_1501 *info1501;
+		SRV_SHARE_INFO_1501 *info1501 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1501, num_entries);
 		int i = 0;
 
-		info1501 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1501));
+		if (!info1501) {
+			return False;
+		}
 
 		for (snum = *resume_hnd; snum < num_services; snum++) {
 			if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
@@ -1137,8 +1157,7 @@
 		int i;
 		if (*total_entries > 0) {
 			ctr->ptr_entries = 1;
-			ctr->file.info3 = talloc(ctx, ctr->num_entries * 
-						 sizeof(SRV_FILE_INFO_3));
+			ctr->file.info3 = TALLOC_ARRAY(ctx, SRV_FILE_INFO_3, ctr->num_entries);
 		}
 		for (i=0 ;i<ctr->num_entries;i++) {
 			init_srv_file_info3(&ctr->file.info3[i].info_3, i+*resume_hnd, 0x35, 0, "\\PIPE\\samr", "dummy user");
@@ -1189,7 +1208,7 @@
 WERROR _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV_R_NET_SRV_GET_INFO *r_u)
 {
 	WERROR status = WERR_OK;
-	SRV_INFO_CTR *ctr = (SRV_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_INFO_CTR));
+	SRV_INFO_CTR *ctr = TALLOC_P(p->mem_ctx, SRV_INFO_CTR);
 
 	if (!ctr)
 		return WERR_NOMEM;
@@ -1292,7 +1311,7 @@
 {
 	DEBUG(5,("srv_net_conn_enum: %d\n", __LINE__));
 
-	r_u->ctr = (SRV_CONN_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_CONN_INFO_CTR));
+	r_u->ctr = TALLOC_P(p->mem_ctx, SRV_CONN_INFO_CTR);
 	if (!r_u->ctr)
 		return WERR_NOMEM;
 
@@ -1317,7 +1336,7 @@
 {
 	DEBUG(5,("_srv_net_sess_enum: %d\n", __LINE__));
 
-	r_u->ctr = (SRV_SESS_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_SESS_INFO_CTR));
+	r_u->ctr = TALLOC_P(p->mem_ctx, SRV_SESS_INFO_CTR);
 	if (!r_u->ctr)
 		return WERR_NOMEM;
 
@@ -1800,7 +1819,7 @@
 	struct tm *t;
 	time_t unixdate = time(NULL);
 
-	tod = (TIME_OF_DAY_INFO *)talloc(p->mem_ctx, sizeof(TIME_OF_DAY_INFO));
+	tod = TALLOC_P(p->mem_ctx, TIME_OF_DAY_INFO);
 	if (!tod)
 		return WERR_NOMEM;
 
@@ -2119,18 +2138,10 @@
 
 	r_u->disk_enum_ctr.unknown = 0; 
 
-	{
-		DISK_INFO *dinfo;
-
-		int dinfo_size = MAX_SERVER_DISK_ENTRIES * sizeof(*dinfo);
-	  
-		if(!(dinfo =  talloc(ctx, dinfo_size))) {
+	if(!(r_u->disk_enum_ctr.disk_info =  TALLOC_ARRAY(ctx, DISK_INFO, MAX_SERVER_DISK_ENTRIES))) {
 			return WERR_NOMEM;
 		}
 
-		r_u->disk_enum_ctr.disk_info = dinfo;
-	}
-
 	r_u->disk_enum_ctr.disk_info_ptr = r_u->disk_enum_ctr.disk_info ? 1 : 0;
 
 	/*allow one DISK_INFO for null terminator*/
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_util.c samba-3.0.9/source/rpc_server/srv_util.c
--- samba-3.0.9-orig/source/rpc_server/srv_util.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_util.c	2004-12-09 09:00:27.298591216 -0600
@@ -276,7 +276,7 @@
 	
 	if (n_unix_groups > 0) {
 	
-		*pgids   = talloc(ctx, sizeof(DOM_GID) * n_unix_groups);
+		*pgids   = TALLOC_ARRAY(ctx, DOM_GID, n_unix_groups);
 		
 		if (!*pgids) {
 			DEBUG(0, ("get_user_group: malloc() failed for DOM_GID list!\n"));
@@ -324,7 +324,7 @@
 	DOM_GID *gids;
 	int i;
 
-	gids = (DOM_GID *)talloc(mem_ctx, sizeof(*gids) * nt_token->num_sids);
+	gids = TALLOC_ARRAY(mem_ctx, DOM_GID, nt_token->num_sids);
 
 	if (!gids) {
 		return NT_STATUS_NO_MEMORY;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/rpc_server/srv_wkssvc_nt.c samba-3.0.9/source/rpc_server/srv_wkssvc_nt.c
--- samba-3.0.9-orig/source/rpc_server/srv_wkssvc_nt.c	2004-11-15 21:03:22.000000000 -0600
+++ samba-3.0.9/source/rpc_server/srv_wkssvc_nt.c	2004-12-09 09:00:27.308588732 -0600
@@ -65,7 +65,7 @@
 
 	DEBUG(5,("_wks_query_info: %d\n", __LINE__));
 
-	wks100 = (WKS_INFO_100 *)talloc_zero(p->mem_ctx, sizeof(WKS_INFO_100));
+	wks100 = TALLOC_ZERO_P(p->mem_ctx, WKS_INFO_100);
 
 	if (!wks100)
 		return NT_STATUS_NO_MEMORY;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/sam/idmap.c samba-3.0.9/source/sam/idmap.c
--- samba-3.0.9-orig/source/sam/idmap.c	2004-11-15 21:03:26.000000000 -0600
+++ samba-3.0.9/source/sam/idmap.c	2004-12-09 09:00:27.502540546 -0600
@@ -83,7 +83,7 @@
 		return NT_STATUS_OBJECT_NAME_COLLISION;
 	}
 
-	entry = smb_xmalloc(sizeof(struct idmap_function_entry));
+	entry = SMB_XMALLOC_P(struct idmap_function_entry);
 	entry->name = smb_xstrdup(name);
 	entry->methods = methods;
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/sam/idmap_tdb.c samba-3.0.9/source/sam/idmap_tdb.c
--- samba-3.0.9-orig/source/sam/idmap_tdb.c	2004-11-15 21:03:26.000000000 -0600
+++ samba-3.0.9/source/sam/idmap_tdb.c	2004-12-09 09:00:27.500541043 -0600
@@ -487,7 +487,7 @@
 	BOOL tdb_is_new = False;
 
 	/* use the old database if present */
-	tdbfile = strdup(lock_path("winbindd_idmap.tdb"));
+	tdbfile = SMB_STRDUP(lock_path("winbindd_idmap.tdb"));
 	if (!tdbfile) {
 		DEBUG(0, ("idmap_init: out of memory!\n"));
 		return NT_STATUS_NO_MEMORY;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/blocking.c samba-3.0.9/source/smbd/blocking.c
--- samba-3.0.9-orig/source/smbd/blocking.c	2004-11-15 21:03:13.000000000 -0600
+++ samba-3.0.9/source/smbd/blocking.c	2004-12-09 09:00:27.036656292 -0600
@@ -106,12 +106,12 @@
 	 * the expiration time here.
 	 */
 
-	if((blr = (blocking_lock_record *)malloc(sizeof(blocking_lock_record))) == NULL) {
+	if((blr = SMB_MALLOC_P(blocking_lock_record)) == NULL) {
 		DEBUG(0,("push_blocking_lock_request: Malloc fail !\n" ));
 		return False;
 	}
 
-	if((blr->inbuf = (char *)malloc(length)) == NULL) {
+	if((blr->inbuf = (char *)SMB_MALLOC(length)) == NULL) {
 		DEBUG(0,("push_blocking_lock_request: Malloc fail (2)!\n" ));
 		SAFE_FREE(blr);
 		return False;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/conn.c samba-3.0.9/source/smbd/conn.c
--- samba-3.0.9-orig/source/smbd/conn.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/conn.c	2004-12-09 09:00:27.054651821 -0600
@@ -132,7 +132,7 @@
 		return NULL;
 	}
 
-	if ((conn=(connection_struct *)talloc_zero(mem_ctx, sizeof(*conn)))==NULL) {
+	if ((conn=TALLOC_ZERO_P(mem_ctx, connection_struct))==NULL) {
 		DEBUG(0,("talloc_zero() failed!\n"));
 		return NULL;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/dir.c samba-3.0.9/source/smbd/dir.c
--- samba-3.0.9-orig/source/smbd/dir.c	2004-11-15 21:03:15.000000000 -0600
+++ samba-3.0.9/source/smbd/dir.c	2004-12-09 09:00:27.085644122 -0600
@@ -407,7 +407,7 @@
 	if (dptrs_open >= MAX_OPEN_DIRECTORIES)
 		dptr_idleoldest();
 
-	dptr = (dptr_struct *)malloc(sizeof(dptr_struct));
+	dptr = SMB_MALLOC_P(dptr_struct);
 	if(!dptr) {
 		DEBUG(0,("malloc fail in dptr_create.\n"));
 		return -1;
@@ -819,7 +819,7 @@
 
 	if (!p)
 		return(NULL);
-	dirp = (Dir *)malloc(sizeof(Dir));
+	dirp = SMB_MALLOC_P(Dir);
 	if (!dirp) {
 		DEBUG(0,("Out of memory in OpenDir\n"));
 		SMB_VFS_CLOSEDIR(conn,p);
@@ -900,7 +900,7 @@
 		if (used + l > dirp->mallocsize) {
 			int s = MAX(used+l,used+2000);
 			char *r;
-			r = (char *)Realloc(dirp->data,s);
+			r = (char *)SMB_REALLOC(dirp->data,s);
 			if (!r) {
 				DEBUG(0,("Out of memory in OpenDir\n"));
 					break;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/fake_file.c samba-3.0.9/source/smbd/fake_file.c
--- samba-3.0.9-orig/source/smbd/fake_file.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/fake_file.c	2004-12-09 09:00:27.060650331 -0600
@@ -132,7 +132,7 @@
 				return NULL;	
 			}
 
-			if ((fh =(FAKE_FILE_HANDLE *)talloc_zero(mem_ctx, sizeof(FAKE_FILE_HANDLE)))==NULL) {
+			if ((fh =TALLOC_ZERO_P(mem_ctx, FAKE_FILE_HANDLE))==NULL) {
 				DEBUG(0,("talloc_zero() failed.\n"));
 				talloc_destroy(mem_ctx);
 				return NULL;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/fileio.c samba-3.0.9/source/smbd/fileio.c
--- samba-3.0.9-orig/source/smbd/fileio.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/fileio.c	2004-12-09 09:00:27.072647350 -0600
@@ -662,7 +662,7 @@
 	if(alloc_size == 0 || fsp->wcp)
 		return False;
 
-	if((wcp = (write_cache *)malloc(sizeof(write_cache))) == NULL) {
+	if((wcp = SMB_MALLOC_P(write_cache)) == NULL) {
 		DEBUG(0,("setup_write_cache: malloc fail.\n"));
 		return False;
 	}
@@ -671,7 +671,7 @@
 	wcp->offset = 0;
 	wcp->alloc_size = alloc_size;
 	wcp->data_size = 0;
-	if((wcp->data = malloc(wcp->alloc_size)) == NULL) {
+	if((wcp->data = SMB_MALLOC(wcp->alloc_size)) == NULL) {
 		DEBUG(0,("setup_write_cache: malloc fail for buffer size %u.\n",
 			(unsigned int)wcp->alloc_size ));
 		SAFE_FREE(wcp);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/files.c samba-3.0.9/source/smbd/files.c
--- samba-3.0.9-orig/source/smbd/files.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/files.c	2004-12-09 09:00:27.059650579 -0600
@@ -93,7 +93,7 @@
 		return NULL;
 	}
 
-	fsp = (files_struct *)malloc(sizeof(*fsp));
+	fsp = SMB_MALLOC_P(files_struct);
 	if (!fsp) {
 		unix_ERR_class = ERRSRV;
 		unix_ERR_code = ERRnofids;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/ipc.c samba-3.0.9/source/smbd/ipc.c
--- samba-3.0.9-orig/source/smbd/ipc.c	2004-11-15 21:03:13.000000000 -0600
+++ samba-3.0.9/source/smbd/ipc.c	2004-12-09 09:00:27.026658776 -0600
@@ -165,7 +165,7 @@
 static BOOL api_rpc_trans_reply(char *outbuf, smb_np_struct *p)
 {
 	BOOL is_data_outstanding;
-	char *rdata = malloc(p->max_trans_reply);
+	char *rdata = SMB_MALLOC(p->max_trans_reply);
 	int data_len;
 
 	if(rdata == NULL) {
@@ -389,7 +389,7 @@
 		goto bad_param;
   
 	if (tdscnt)  {
-		if((data = (char *)malloc(tdscnt)) == NULL) {
+		if((data = (char *)SMB_MALLOC(tdscnt)) == NULL) {
 			DEBUG(0,("reply_trans: data malloc fail for %u bytes !\n", tdscnt));
 			END_PROFILE(SMBtrans);
 			return(ERROR_DOS(ERRDOS,ERRnomem));
@@ -404,7 +404,7 @@
 	}
 
 	if (tpscnt) {
-		if((params = (char *)malloc(tpscnt)) == NULL) {
+		if((params = (char *)SMB_MALLOC(tpscnt)) == NULL) {
 			DEBUG(0,("reply_trans: param malloc fail for %u bytes !\n", tpscnt));
 			SAFE_FREE(data);
 			END_PROFILE(SMBtrans);
@@ -421,7 +421,7 @@
 
 	if (suwcnt) {
 		unsigned int i;
-		if((setup = (uint16 *)malloc(suwcnt*sizeof(uint16))) == NULL) {
+		if((setup = SMB_MALLOC_ARRAY(uint16,suwcnt)) == NULL) {
 			DEBUG(0,("reply_trans: setup malloc fail for %u bytes !\n", (unsigned int)(suwcnt * sizeof(uint16))));
 			SAFE_FREE(data);
 			SAFE_FREE(params);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/lanman.c samba-3.0.9/source/smbd/lanman.c
--- samba-3.0.9-orig/source/smbd/lanman.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/lanman.c	2004-12-09 09:00:27.069648096 -0600
@@ -753,7 +753,7 @@
 		 */
 		*rdata_len = 0;
 		*rparam_len = 6;
-		*rparam = REALLOC(*rparam,*rparam_len);
+		*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 		SSVALS(*rparam,0,ERRunknownlevel);
 		SSVAL(*rparam,2,0);
 		SSVAL(*rparam,4,0);
@@ -780,7 +780,7 @@
 	}
 
 	if (mdrcnt > 0) {
-		*rdata = REALLOC(*rdata,mdrcnt);
+		*rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
 		desc.base = *rdata;
 		desc.buflen = mdrcnt;
 	} else {
@@ -789,7 +789,7 @@
 		 * init_package will return wrong size if buflen=0
 		 */
 		desc.buflen = getlen(desc.format);
-		desc.base = tmpdata = (char *) malloc (desc.buflen);
+		desc.base = tmpdata = (char *) SMB_MALLOC (desc.buflen);
 	}
 
 	if (init_package(&desc,1,count)) {
@@ -809,7 +809,7 @@
  
 	*rdata_len = desc.usedlen;
 	*rparam_len = 6;
-	*rparam = REALLOC(*rparam,*rparam_len);
+	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 	SSVALS(*rparam,0,desc.errcode);
 	SSVAL(*rparam,2,0);
 	SSVAL(*rparam,4,desc.neededlen);
@@ -857,7 +857,7 @@
      */
     *rdata_len = 0;
     *rparam_len = 6;
-    *rparam = REALLOC(*rparam,*rparam_len);
+    *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
     SSVALS(*rparam,0,ERRunknownlevel);
     SSVAL(*rparam,2,0);
     SSVAL(*rparam,4,0);
@@ -869,17 +869,17 @@
     if (lp_snum_ok(i) && lp_print_ok(i) && lp_browseable(i))
       queuecnt++;
   if (uLevel > 0) {
-    if((queue = (print_queue_struct**)malloc(queuecnt*sizeof(print_queue_struct*))) == NULL) {
+    if((queue = SMB_MALLOC_ARRAY(print_queue_struct*, queuecnt)) == NULL) {
       DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
       return False;
     }
     memset(queue,0,queuecnt*sizeof(print_queue_struct*));
-    if((status = (print_status_struct*)malloc(queuecnt*sizeof(print_status_struct))) == NULL) {
+    if((status = SMB_MALLOC_ARRAY(print_status_struct,queuecnt)) == NULL) {
       DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
       return False;
     }
     memset(status,0,queuecnt*sizeof(print_status_struct));
-    if((subcntarr = (int*)malloc(queuecnt*sizeof(int))) == NULL) {
+    if((subcntarr = SMB_MALLOC_ARRAY(int,queuecnt)) == NULL) {
       DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
       return False;
     }
@@ -892,7 +892,7 @@
  	n++;
       }
   }
-  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
   desc.base = *rdata;
   desc.buflen = mdrcnt;
 
@@ -911,7 +911,7 @@
  
   *rdata_len = desc.usedlen;
   *rparam_len = 8;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVALS(*rparam,0,desc.errcode);
   SSVAL(*rparam,2,0);
   SSVAL(*rparam,4,succnt);
@@ -995,8 +995,7 @@
       struct srv_info_struct *ts;
       
       alloced += 10;
-      ts = (struct srv_info_struct *)
-	Realloc(*servers,sizeof(**servers)*alloced);
+      ts = SMB_REALLOC_ARRAY(*servers,struct srv_info_struct, alloced);
       if (!ts) {
       	DEBUG(0,("get_server_info: failed to enlarge servers info struct!\n"));
 	return(0);
@@ -1242,7 +1241,7 @@
   }
 
   *rdata_len = fixed_len + string_len;
-  *rdata = REALLOC(*rdata,*rdata_len);
+  *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
   memset(*rdata,'\0',*rdata_len);
   
   p2 = (*rdata) + fixed_len;	/* auxilliary data (strings) will go here */
@@ -1266,7 +1265,7 @@
   }
   
   *rparam_len = 8;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVAL(*rparam,0,(missed == 0 ? NERR_Success : ERRmoredata));
   SSVAL(*rparam,2,0);
   SSVAL(*rparam,4,counted);
@@ -1303,7 +1302,7 @@
   *rdata_len = 0;
   
   *rparam_len = 8;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 
   SSVAL(*rparam,0,0x08AC); /* informational warning message */
   SSVAL(*rparam,2,0);
@@ -1449,13 +1448,13 @@
   if (!prefix_ok(str1,"zWrLh")) return False;
   if (!check_share_info(uLevel,str2)) return False;
  
-  *rdata = REALLOC(*rdata,mdrcnt);
+  *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
   p = *rdata;
   *rdata_len = fill_share_info(conn,snum,uLevel,&p,&mdrcnt,0,0,0);
   if (*rdata_len < 0) return False;
  
   *rparam_len = 6;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVAL(*rparam,0,NERR_Success);
   SSVAL(*rparam,2,0);		/* converter word */
   SSVAL(*rparam,4,*rdata_len);
@@ -1520,7 +1519,7 @@
     }
   }
   *rdata_len = fixed_len + string_len;
-  *rdata = REALLOC(*rdata,*rdata_len);
+  *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
   memset(*rdata,0,*rdata_len);
   
   p2 = (*rdata) + fixed_len;	/* auxiliary data (strings) will go here */
@@ -1541,7 +1540,7 @@
     }
   
   *rparam_len = 8;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVAL(*rparam,0,missed ? ERRmoredata : NERR_Success);
   SSVAL(*rparam,2,0);
   SSVAL(*rparam,4,counted);
@@ -1627,7 +1626,7 @@
   } else return False;
 
   *rparam_len = 6;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVAL(*rparam,0,NERR_Success);
   SSVAL(*rparam,2,0);		/* converter word */
   SSVAL(*rparam,4,*rdata_len);
@@ -1637,7 +1636,7 @@
 
  error_exit:
   *rparam_len = 4;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   *rdata_len = 0;
   SSVAL(*rparam,0,res);
   SSVAL(*rparam,2,0);
@@ -1692,7 +1691,7 @@
 	DEBUG(10,("api_RNetGroupEnum:resume context: %d, client buffer size: %d\n", resume_context, cli_buf_size));
 
 	*rdata_len = cli_buf_size;
-	*rdata = REALLOC(*rdata,*rdata_len);
+	*rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
 
 	p = *rdata;
 
@@ -1714,7 +1713,7 @@
 	*rdata_len = PTR_DIFF(p,*rdata);
 
 	*rparam_len = 8;
-	*rparam = REALLOC(*rparam,*rparam_len);
+	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 
   	SSVAL(*rparam, 0, errflags);
   	SSVAL(*rparam, 2, 0);		/* converter word */
@@ -1750,7 +1749,7 @@
 	DOM_SID sid, dom_sid;
 
 	*rparam_len = 8;
-	*rparam = REALLOC(*rparam,*rparam_len);
+	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   
 	/* check it's a supported varient */
 	
@@ -1769,7 +1768,7 @@
 		return False;
 
 	*rdata_len = mdrcnt + 1024;
-	*rdata = REALLOC(*rdata,*rdata_len);
+	*rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
 
 	SSVAL(*rparam,0,NERR_Success);
 	SSVAL(*rparam,2,0);		/* converter word */
@@ -1864,14 +1863,14 @@
 	DEBUG(10,("api_RNetUserEnum:resume context: %d, client buffer size: %d\n", resume_context, cli_buf_size));
 
 	*rparam_len = 8;
-	*rparam = REALLOC(*rparam,*rparam_len);
+	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 
 	/* check it's a supported varient */
 	if (strcmp("B21",str2) != 0)
 		return False;
 
 	*rdata_len = cli_buf_size;
-	*rdata = REALLOC(*rdata,*rdata_len);
+	*rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
 
 	p = *rdata;
 
@@ -1934,10 +1933,10 @@
 {
   char *p;
   *rparam_len = 4;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 
   *rdata_len = 21;
-  *rdata = REALLOC(*rdata,*rdata_len);
+  *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
 
   SSVAL(*rparam,0,NERR_Success);
   SSVAL(*rparam,2,0);		/* converter word */
@@ -1996,7 +1995,7 @@
 	memcpy(pass2,p+16,16);
 
 	*rparam_len = 4;
-	*rparam = REALLOC(*rparam,*rparam_len);
+	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 
 	*rdata_len = 0;
 
@@ -2068,7 +2067,7 @@
 	fstring user;
 	char *p = param + 2;
 	*rparam_len = 2;
-	*rparam = REALLOC(*rparam,*rparam_len);
+	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 
 	*rdata_len = 0;
 
@@ -2135,7 +2134,7 @@
 		return(False);
 
 	*rparam_len = 4;
-	*rparam = REALLOC(*rparam,*rparam_len);	
+	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);	
 	*rdata_len = 0;
 
 	if (!print_job_exists(sharename, jobid)) {
@@ -2192,7 +2191,7 @@
 		return(False);
 
 	*rparam_len = 4;
-	*rparam = REALLOC(*rparam,*rparam_len);
+	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 	*rdata_len = 0;
 
 	snum = print_queue_snum(QueueName);
@@ -2266,7 +2265,7 @@
 	if(!rap_to_pjobid(SVAL(p,0), sharename, &jobid))
 		return False;
 	*rparam_len = 4;
-	*rparam = REALLOC(*rparam,*rparam_len);
+	*rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 
 	if ( (snum = lp_servicenumber(sharename)) == -1 ) {
 		DEBUG(0,("api_PrintJobInfo: unable to get service number from sharename [%s]\n",
@@ -2367,7 +2366,7 @@
   }
 
   *rdata_len = mdrcnt;
-  *rdata = REALLOC(*rdata,*rdata_len);
+  *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
 
   p = *rdata;
   p2 = p + struct_len;
@@ -2416,7 +2415,7 @@
   *rdata_len = PTR_DIFF(p2,*rdata);
 
   *rparam_len = 6;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVAL(*rparam,0,NERR_Success);
   SSVAL(*rparam,2,0);		/* converter word */
   SSVAL(*rparam,4,*rdata_len);
@@ -2443,14 +2442,14 @@
   DEBUG(4,("NetWkstaGetInfo level %d\n",level));
 
   *rparam_len = 6;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 
   /* check it's a supported varient */
   if (!(level==10 && strcsequal(str1,"WrLh") && strcsequal(str2,"zzzBBzz")))
     return(False);
 
   *rdata_len = mdrcnt + 1024;
-  *rdata = REALLOC(*rdata,*rdata_len);
+  *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
 
   SSVAL(*rparam,0,NERR_Success);
   SSVAL(*rparam,2,0);		/* converter word */
@@ -2689,7 +2688,7 @@
 	       vuser->user.unix_name));
 
     *rparam_len = 6;
-    *rparam = REALLOC(*rparam,*rparam_len);
+    *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 
     DEBUG(4,("RNetUserGetInfo level=%d\n", uLevel));
   
@@ -2708,7 +2707,7 @@
 	if (strcmp(level_string,str2) != 0) return False;
 
 	*rdata_len = mdrcnt + 1024;
-	*rdata = REALLOC(*rdata,*rdata_len);
+	*rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
 
 	SSVAL(*rparam,0,NERR_Success);
 	SSVAL(*rparam,2,0);		/* converter word */
@@ -2855,7 +2854,7 @@
   /* check it's a supported varient */
   if (strcmp(str1,"OOWb54WrLh") != 0) return False;
   if (uLevel != 1 || strcmp(str2,"WB21BWDWWDDDDDDDzzzD") != 0) return False;
-  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
   desc.base = *rdata;
   desc.buflen = mdrcnt;
   desc.subformat = NULL;
@@ -2894,7 +2893,7 @@
 
   *rdata_len = desc.usedlen;
   *rparam_len = 6;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVALS(*rparam,0,desc.errcode);
   SSVAL(*rparam,2,0);
   SSVAL(*rparam,4,desc.neededlen);
@@ -2924,7 +2923,7 @@
   if (strcmp(str2,"") != 0) return False;
 
   *rparam_len = 6;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVALS(*rparam,0,0);		/* errorcode */
   SSVAL(*rparam,2,0);		/* converter word */
   SSVAL(*rparam,4,0x7f);	/* permission flags */
@@ -2976,7 +2975,7 @@
   }
 
   if (mdrcnt > 0) {
-    *rdata = REALLOC(*rdata,mdrcnt);
+    *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
     desc.base = *rdata;
     desc.buflen = mdrcnt;
   } else {
@@ -2985,7 +2984,7 @@
      *  init_package will return wrong size if buflen=0
      */
     desc.buflen = getlen(desc.format);
-    desc.base = tmpdata = (char *)malloc ( desc.buflen );
+    desc.base = tmpdata = (char *)SMB_MALLOC( desc.buflen );
   }
 
   if (init_package(&desc,1,0)) {
@@ -3000,7 +2999,7 @@
   }
 
   *rparam_len = 6;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVALS(*rparam,0,desc.errcode);
   SSVAL(*rparam,2,0);
   SSVAL(*rparam,4,desc.neededlen);
@@ -3054,7 +3053,7 @@
   if (snum < 0 || !VALID_SNUM(snum)) return(False);
 
   count = print_queue_status(snum,&queue,&status);
-  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
   desc.base = *rdata;
   desc.buflen = mdrcnt;
 
@@ -3069,7 +3068,7 @@
   *rdata_len = desc.usedlen;
 
   *rparam_len = 8;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVALS(*rparam,0,desc.errcode);
   SSVAL(*rparam,2,0);
   SSVAL(*rparam,4,succnt);
@@ -3170,7 +3169,7 @@
   }
   else {
     if (mdrcnt > 0) {
-      *rdata = REALLOC(*rdata,mdrcnt);
+      *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
       desc.base = *rdata;
       desc.buflen = mdrcnt;
     } else {
@@ -3179,7 +3178,7 @@
        *  init_package will return wrong size if buflen=0
        */
       desc.buflen = getlen(desc.format);
-      desc.base = tmpdata = (char *)malloc ( desc.buflen );
+      desc.base = tmpdata = (char *)SMB_MALLOC( desc.buflen );
     }
     if (init_package(&desc,1,0)) {
       fill_printdest_info(conn,snum,uLevel,&desc);
@@ -3188,7 +3187,7 @@
   }
 
   *rparam_len = 6;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVALS(*rparam,0,desc.errcode);
   SSVAL(*rparam,2,0);
   SSVAL(*rparam,4,desc.neededlen);
@@ -3227,7 +3226,7 @@
     if (lp_snum_ok(i) && lp_print_ok(i) && lp_browseable(i))
       queuecnt++;
 
-  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
   desc.base = *rdata;
   desc.buflen = mdrcnt;
   if (init_package(&desc,queuecnt,0)) {    
@@ -3245,7 +3244,7 @@
   *rdata_len = desc.usedlen;
 
   *rparam_len = 8;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVALS(*rparam,0,desc.errcode);
   SSVAL(*rparam,2,0);
   SSVAL(*rparam,4,succnt);
@@ -3277,7 +3276,7 @@
   if (strcmp(str1,"WrLeh") != 0) return False;
   if (uLevel != 0 || strcmp(str2,"B41") != 0) return False;
 
-  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
   desc.base = *rdata;
   desc.buflen = mdrcnt;
   if (init_package(&desc,1,0)) {
@@ -3289,7 +3288,7 @@
   *rdata_len = desc.usedlen;
 
   *rparam_len = 8;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVALS(*rparam,0,desc.errcode);
   SSVAL(*rparam,2,0);
   SSVAL(*rparam,4,succnt);
@@ -3321,7 +3320,7 @@
   if (strcmp(str1,"WrLeh") != 0) return False;
   if (uLevel != 0 || strcmp(str2,"B13") != 0) return False;
 
-  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
   desc.base = *rdata;
   desc.buflen = mdrcnt;
   desc.format = str2;
@@ -3334,7 +3333,7 @@
   *rdata_len = desc.usedlen;
 
   *rparam_len = 8;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVALS(*rparam,0,desc.errcode);
   SSVAL(*rparam,2,0);
   SSVAL(*rparam,4,succnt);
@@ -3366,7 +3365,7 @@
   if (strcmp(str1,"WrLeh") != 0) return False;
   if (uLevel != 0 || strcmp(str2,"B9") != 0) return False;
 
-  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
   memset((char *)&desc,'\0',sizeof(desc));
   desc.base = *rdata;
   desc.buflen = mdrcnt;
@@ -3380,7 +3379,7 @@
   *rdata_len = desc.usedlen;
 
   *rparam_len = 8;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVALS(*rparam,0,desc.errcode);
   SSVAL(*rparam,2,0);
   SSVAL(*rparam,4,succnt);
@@ -3422,7 +3421,7 @@
 
   num_sessions = list_sessions(&session_list);
 
-  if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+  if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
   memset((char *)&desc,'\0',sizeof(desc));
   desc.base = *rdata;
   desc.buflen = mdrcnt;
@@ -3446,7 +3445,7 @@
   *rdata_len = desc.usedlen;
 
   *rparam_len = 8;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
   SSVALS(*rparam,0,desc.errcode);
   SSVAL(*rparam,2,0); /* converter */
   SSVAL(*rparam,4,num_sessions); /* count */
@@ -3466,7 +3465,7 @@
 			 int *rdata_len,int *rparam_len)
 {
   *rparam_len = MIN(*rparam_len,mprcnt);
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 
   *rdata_len = 0;
 
@@ -3488,7 +3487,7 @@
 			    int *rdata_len,int *rparam_len)
 {
   *rparam_len = 4;
-  *rparam = REALLOC(*rparam,*rparam_len);
+  *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
 
   *rdata_len = 0;
 
@@ -3595,11 +3594,11 @@
 		  return ERROR_NT(NT_STATUS_ACCESS_DENIED);
   }
 
-  rdata = (char *)malloc(1024);
+  rdata = (char *)SMB_MALLOC(1024);
   if (rdata)
     memset(rdata,'\0',1024);
 
-  rparam = (char *)malloc(1024);
+  rparam = (char *)SMB_MALLOC(1024);
   if (rparam)
     memset(rparam,'\0',1024);
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/mangle_hash2.c samba-3.0.9/source/smbd/mangle_hash2.c
--- samba-3.0.9-orig/source/smbd/mangle_hash2.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/mangle_hash2.c	2004-12-09 09:00:27.038655795 -0600
@@ -153,13 +153,19 @@
  */
 static BOOL cache_init(void)
 {
-	if (prefix_cache) return True;
+	if (prefix_cache) {
+		return True;
+	}
 
-	prefix_cache = calloc(MANGLE_CACHE_SIZE, sizeof(char *));
-	if (!prefix_cache) return False;
+	prefix_cache = SMB_CALLOC_ARRAY(char *,MANGLE_CACHE_SIZE);
+	if (!prefix_cache) {
+		return False;
+	}
 
-	prefix_cache_hashes = calloc(MANGLE_CACHE_SIZE, sizeof(u32));
-	if (!prefix_cache_hashes) return False;
+	prefix_cache_hashes = SMB_CALLOC_ARRAY(u32, MANGLE_CACHE_SIZE);
+	if (!prefix_cache_hashes) {
+		return False;
+	}
 
 	return True;
 }
@@ -175,7 +181,7 @@
 		free(prefix_cache[i]);
 	}
 
-	prefix_cache[i] = strndup(prefix, length);
+	prefix_cache[i] = SMB_STRNDUP(prefix, length);
 	prefix_cache_hashes[i] = hash;
 }
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/mangle_hash.c samba-3.0.9/source/smbd/mangle_hash.c
--- samba-3.0.9-orig/source/smbd/mangle_hash.c	2004-11-15 21:03:13.000000000 -0600
+++ samba-3.0.9/source/smbd/mangle_hash.c	2004-12-09 09:00:27.024659273 -0600
@@ -476,7 +476,7 @@
 	if(data_val.dptr == NULL || data_val.dsize == 0) {
 		ext_start = strrchr( s, '.' );
 		if( ext_start ) {
-			if((saved_ext = strdup(ext_start)) == NULL)
+			if((saved_ext = SMB_STRDUP(ext_start)) == NULL)
 				return False;
 
 			*ext_start = '\0';
@@ -624,7 +624,7 @@
 
 		/* mangle it into 8.3 */
 		if (cache83)
-			tmp = strdup(OutName);
+			tmp = SMB_STRDUP(OutName);
 
 		to_8_3(OutName, default_case);
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/msdfs.c samba-3.0.9/source/smbd/msdfs.c
--- samba-3.0.9-orig/source/smbd/msdfs.c	2004-11-15 21:03:13.000000000 -0600
+++ samba-3.0.9/source/smbd/msdfs.c	2004-12-09 09:00:27.028658279 -0600
@@ -189,7 +189,7 @@
 
 	DEBUG(10,("parse_symlink: count=%d\n", count));
 
-	reflist = *preflist = (struct referral*) malloc(count * sizeof(struct referral));
+	reflist = *preflist = SMB_MALLOC_ARRAY(struct referral, count);
 	if(reflist == NULL) {
 		DEBUG(0,("parse_symlink: Malloc failed!\n"));
 		return False;
@@ -417,7 +417,7 @@
 		*self_referralp = True;
 
 	jucn->referral_count = 1;
-	if((ref = (struct referral*) malloc(sizeof(struct referral))) == NULL) {
+	if((ref = SMB_MALLOC_P(struct referral)) == NULL) {
 		DEBUG(0,("self_ref: malloc failed for referral\n"));
 		return False;
 	}
@@ -503,7 +503,7 @@
 					self_referralp);
 
 		jucn->referral_count = 1;
-		if ((ref = (struct referral*) malloc(sizeof(struct referral))) == NULL) {
+		if ((ref = SMB_MALLOC_P(struct referral)) == NULL) {
 			DEBUG(0, ("malloc failed for referral\n"));
 			goto out;
 		}
@@ -595,7 +595,7 @@
 	/* add the unexplained 0x16 bytes */
 	reply_size += 0x16;
 
-	pdata = Realloc(pdata,reply_size);
+	pdata = SMB_REALLOC(pdata,reply_size);
 	if(pdata == NULL) {
 		DEBUG(0,("malloc failed for Realloc!\n"));
 		return -1;
@@ -676,7 +676,7 @@
 		reply_size += (strlen(junction->referral_list[i].alternate_path)+1)*2;
 	}
 
-	pdata = Realloc(pdata,reply_size);
+	pdata = SMB_REALLOC(pdata,reply_size);
 	if(pdata == NULL) {
 		DEBUG(0,("version3 referral setup: malloc failed for Realloc!\n"));
 		return -1;
@@ -962,8 +962,7 @@
 	jucn[cnt].volume_name[0] = '\0';
 	jucn[cnt].referral_count = 1;
 
-	ref = jucn[cnt].referral_list
-		= (struct referral*) malloc(sizeof(struct referral));
+	ref = jucn[cnt].referral_list = SMB_MALLOC_P(struct referral);
 	if (jucn[cnt].referral_list == NULL) {
 		DEBUG(0, ("Malloc failed!\n"));
 		goto out;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/notify.c samba-3.0.9/source/smbd/notify.c
--- samba-3.0.9-orig/source/smbd/notify.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/notify.c	2004-12-09 09:00:27.075646605 -0600
@@ -178,7 +178,7 @@
 {
 	struct change_notify *cnbp;
 
-	if((cnbp = (struct change_notify *)malloc(sizeof(*cnbp))) == NULL) {
+	if((cnbp = SMB_MALLOC_P(struct change_notify)) == NULL) {
 		DEBUG(0,("change_notify_set: malloc fail !\n" ));
 		return -1;
 	}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/ntquotas.c samba-3.0.9/source/smbd/ntquotas.c
--- samba-3.0.9-orig/source/smbd/ntquotas.c	2004-11-15 21:03:15.000000000 -0600
+++ samba-3.0.9/source/smbd/ntquotas.c	2004-12-09 09:00:27.083644618 -0600
@@ -199,14 +199,14 @@
 		DEBUG(15,("quota entry for id[%s] path[%s]\n",
 			sid_string_static(&sid),fsp->conn->connectpath));
 
-		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"));
 			*qt_list = NULL;
 			talloc_destroy(mem_ctx);
 			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"));
 			*qt_list = NULL;
 			talloc_destroy(mem_ctx);
@@ -232,7 +232,7 @@
 	if (!mem_ctx)
 		return False;
 
-	qt_handle = (SMB_NTQUOTA_HANDLE *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_HANDLE));
+	qt_handle = TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_HANDLE);
 	if (qt_handle==NULL) {
 		DEBUG(0,("talloc_zero() failed\n"));
 		return NULL;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/nttrans.c samba-3.0.9/source/smbd/nttrans.c
--- samba-3.0.9-orig/source/smbd/nttrans.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/nttrans.c	2004-12-09 09:00:27.043654554 -0600
@@ -58,11 +58,12 @@
 	if (ptr==NULL)
 		smb_panic("nttrans_realloc() called with NULL ptr\n");
 		
-	tptr = Realloc_zero(*ptr, size);
+	tptr = SMB_REALLOC(*ptr, size);
 	if(tptr == NULL) {
 		*ptr = NULL;
 		return NULL;
 	}
+	memset(tptr,'\0',size);
 
 	*ptr = tptr;
 
@@ -2141,7 +2142,7 @@
 			return ERROR_NT(NT_STATUS_NO_MEMORY);
 		}
 
-		shadow_data = (SHADOW_COPY_DATA *)talloc_zero(shadow_mem_ctx,sizeof(SHADOW_COPY_DATA));
+		shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
 		if (shadow_data == NULL) {
 			DEBUG(0,("talloc_zero() failed!\n"));
 			return ERROR_NT(NT_STATUS_NO_MEMORY);
@@ -2452,6 +2453,10 @@
 			}
 
 			sid_len = IVAL(pdata,4);
+			/* Ensure this is less than 1mb. */
+			if (sid_len > (1024*1024)) {
+				return ERROR_DOS(ERRDOS,ERRnomem);
+			}
 
 			if (data_count < 8+sid_len) {
 				DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
@@ -2707,14 +2712,20 @@
 		goto bad_param;
 	}
     
+	/* Don't allow more than 128mb for each value. */
+	if ((total_parameter_count > (1024*1024*128)) || (total_data_count > (1024*1024*128))) {
+		END_PROFILE(SMBnttrans);
+		return ERROR_DOS(ERRDOS,ERRnomem);
+	}
+
 	/* Allocate the space for the setup, the maximum needed parameters and data */
 
 	if(setup_count > 0)
-		setup = (char *)malloc(setup_count);
+		setup = (char *)SMB_MALLOC(setup_count);
 	if (total_parameter_count > 0)
-		params = (char *)malloc(total_parameter_count);
+		params = (char *)SMB_MALLOC(total_parameter_count);
 	if (total_data_count > 0)
-		data = (char *)malloc(total_data_count);
+		data = (char *)SMB_MALLOC(total_data_count);
  
 	if ((total_parameter_count && !params)  || (total_data_count && !data) ||
 				(setup_count && !setup)) {
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/open.c samba-3.0.9/source/smbd/open.c
--- samba-3.0.9-orig/source/smbd/open.c	2004-11-15 21:03:13.000000000 -0600
+++ samba-3.0.9/source/smbd/open.c	2004-12-09 09:00:27.010662750 -0600
@@ -681,7 +681,7 @@
 					return -1;
 				}
 				
-				broken_entry = malloc(sizeof(struct share_mode_entry_list));
+				broken_entry = SMB_MALLOC_P(struct share_mode_entry_list);
 				if (!broken_entry) {
 					smb_panic("open_mode_check: malloc fail.\n");
 				}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/oplock.c samba-3.0.9/source/smbd/oplock.c
--- samba-3.0.9-orig/source/smbd/oplock.c	2004-11-15 21:03:13.000000000 -0600
+++ samba-3.0.9/source/smbd/oplock.c	2004-12-09 09:00:27.034656789 -0600
@@ -740,12 +740,12 @@
 	 * messages crossing on the wire.
 	 */
 
-	if((inbuf = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
+	if((inbuf = (char *)SMB_MALLOC(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
 		DEBUG(0,("oplock_break: malloc fail for input buffer.\n"));
 		return False;
 	}
 
-	if((outbuf = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
+	if((outbuf = (char *)SMB_MALLOC(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
 		DEBUG(0,("oplock_break: malloc fail for output buffer.\n"));
 		SAFE_FREE(inbuf);
 		return False;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/password.c samba-3.0.9/source/smbd/password.c
--- samba-3.0.9-orig/source/smbd/password.c	2004-11-15 21:03:13.000000000 -0600
+++ samba-3.0.9/source/smbd/password.c	2004-12-09 09:00:27.012662253 -0600
@@ -139,7 +139,7 @@
 		return UID_FIELD_INVALID;
 	}
 
-	if((vuser = (user_struct *)malloc( sizeof(user_struct) )) == NULL) {
+	if((vuser = SMB_MALLOC_P(user_struct)) == NULL) {
 		DEBUG(0,("Failed to malloc users struct!\n"));
 		data_blob_free(&session_key);
 		return UID_FIELD_INVALID;
@@ -316,7 +316,7 @@
 			DEBUG(3,("add_session_user: session userlist already too large.\n"));
 			return;
 		}
-		newlist = Realloc( session_userlist, len_session_userlist + PSTRING_LEN );
+		newlist = SMB_REALLOC( session_userlist, len_session_userlist + PSTRING_LEN );
 		if( newlist == NULL ) {
 			DEBUG(1,("Unable to resize session_userlist\n"));
 			return;
@@ -498,9 +498,9 @@
 		char *user_list = NULL;
 
 		if ( session_userlist )
-			user_list = strdup(session_userlist);
+			user_list = SMB_STRDUP(session_userlist);
 		else
-			user_list = strdup("");
+			user_list = SMB_STRDUP("");
 
 		if (!user_list)
 			return(False);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/posix_acls.c samba-3.0.9/source/smbd/posix_acls.c
--- samba-3.0.9-orig/source/smbd/posix_acls.c	2004-11-15 21:03:13.000000000 -0600
+++ samba-3.0.9/source/smbd/posix_acls.c	2004-12-09 09:00:27.022659770 -0600
@@ -166,7 +166,7 @@
 
 	*store_size = PAI_ENTRIES_BASE + ((num_entries + num_def_entries)*PAI_ENTRY_LENGTH);
 
-	pai_buf = malloc(*store_size);
+	pai_buf = SMB_MALLOC(*store_size);
 	if (!pai_buf) {
 		return NULL;
 	}
@@ -343,7 +343,7 @@
 	if (!check_pai_ok(buf, size))
 		return NULL;
 
-	paiv = malloc(sizeof(struct pai_val));
+	paiv = SMB_MALLOC_P(struct pai_val);
 	if (!paiv)
 		return NULL;
 
@@ -362,7 +362,7 @@
 	for (i = 0; i < paiv->num_entries; i++) {
 		struct pai_entry *paie;
 
-		paie = malloc(sizeof(struct pai_entry));
+		paie = SMB_MALLOC_P(struct pai_entry);
 		if (!paie) {
 			free_inherited_info(paiv);
 			return NULL;
@@ -393,7 +393,7 @@
 	for (i = 0; i < paiv->num_def_entries; i++) {
 		struct pai_entry *paie;
 
-		paie = malloc(sizeof(struct pai_entry));
+		paie = SMB_MALLOC_P(struct pai_entry);
 		if (!paie) {
 			free_inherited_info(paiv);
 			return NULL;
@@ -438,7 +438,7 @@
 	if (!lp_map_acl_inherit(SNUM(fsp->conn)))
 		return NULL;
 
-	if ((pai_buf = malloc(pai_buf_size)) == NULL)
+	if ((pai_buf = SMB_MALLOC(pai_buf_size)) == NULL)
 		return NULL;
 
 	do {
@@ -456,7 +456,10 @@
 			/* Buffer too small - enlarge it. */
 			pai_buf_size *= 2;
 			SAFE_FREE(pai_buf);
-			if ((pai_buf = malloc(pai_buf_size)) == NULL)
+			if (pai_buf_size > 1024*1024) {
+				return NULL; /* Limit malloc to 1mb. */
+			}
+			if ((pai_buf = SMB_MALLOC(pai_buf_size)) == NULL)
 				return NULL;
 		}
 	} while (ret == -1);
@@ -523,7 +526,7 @@
 
 static canon_ace *dup_canon_ace( canon_ace *src_ace)
 {
-	canon_ace *dst_ace = (canon_ace *)malloc(sizeof(canon_ace));
+	canon_ace *dst_ace = SMB_MALLOC_P(canon_ace);
 
 	if (dst_ace == NULL)
 		return NULL;
@@ -1083,7 +1086,7 @@
 	}
 
 	if (!got_user) {
-		if ((pace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
+		if ((pace = SMB_MALLOC_P(canon_ace)) == NULL) {
 			DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
 			return False;
 		}
@@ -1113,7 +1116,7 @@
 	}
 
 	if (!got_grp) {
-		if ((pace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
+		if ((pace = SMB_MALLOC_P(canon_ace)) == NULL) {
 			DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
 			return False;
 		}
@@ -1139,7 +1142,7 @@
 	}
 
 	if (!got_other) {
-		if ((pace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
+		if ((pace = SMB_MALLOC_P(canon_ace)) == NULL) {
 			DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
 			return False;
 		}
@@ -1323,7 +1326,7 @@
 		 * Create a cannon_ace entry representing this NT DACL ACE.
 		 */
 
-		if ((current_ace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
+		if ((current_ace = SMB_MALLOC_P(canon_ace)) == NULL) {
 			free_canon_ace_list(file_ace);
 			free_canon_ace_list(dir_ace);
 			DEBUG(0,("create_canon_ace_lists: malloc fail.\n"));
@@ -2161,7 +2164,7 @@
 		 * Add this entry to the list.
 		 */
 
-		if ((ace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL)
+		if ((ace = SMB_MALLOC_P(canon_ace)) == NULL)
 			goto fail;
 
 		ZERO_STRUCTP(ace);
@@ -2793,7 +2796,7 @@
 			num_dir_acls = count_canon_ace_list(dir_ace);
 
 			/* Allocate the ace list. */
-			if ((nt_ace_list = (SEC_ACE *)malloc((num_acls + num_profile_acls + num_dir_acls)* sizeof(SEC_ACE))) == NULL) {
+			if ((nt_ace_list = SMB_MALLOC_ARRAY(SEC_ACE, num_acls + num_profile_acls + num_dir_acls)) == NULL) {
 				DEBUG(0,("get_nt_acl: Unable to malloc space for nt_ace_list.\n"));
 				goto done;
 			}
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/process.c samba-3.0.9/source/smbd/process.c
--- samba-3.0.9-orig/source/smbd/process.c	2004-11-15 21:03:13.000000000 -0600
+++ samba-3.0.9/source/smbd/process.c	2004-12-09 09:00:27.031657534 -0600
@@ -85,8 +85,7 @@
 static BOOL push_queued_message(enum q_type qt, char *buf, int msg_len, struct timeval *ptv, char *private, size_t private_len)
 {
 	struct pending_message_list *tmp_msg;
-	struct pending_message_list *msg = (struct pending_message_list *)
-                               malloc(sizeof(struct pending_message_list));
+	struct pending_message_list *msg = SMB_MALLOC_P(struct pending_message_list);
 
 	if(msg == NULL) {
 		DEBUG(0,("push_message: malloc fail (1)\n"));
@@ -1498,8 +1497,8 @@
 	unsigned int num_smbs = 0;
 	const size_t total_buffer_size = BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN;
 
-	InBuffer = (char *)malloc(total_buffer_size);
-	OutBuffer = (char *)malloc(total_buffer_size);
+	InBuffer = (char *)SMB_MALLOC(total_buffer_size);
+	OutBuffer = (char *)SMB_MALLOC(total_buffer_size);
 	if ((InBuffer == NULL) || (OutBuffer == NULL)) 
 		return;
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/reply.c samba-3.0.9/source/smbd/reply.c
--- samba-3.0.9-orig/source/smbd/reply.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/reply.c	2004-12-09 09:00:27.052652318 -0600
@@ -900,7 +900,7 @@
 				END_PROFILE(SMBsearch);
 				return ERROR_DOS(ERRDOS,ERRnofids);
 			}
-			dptr_set_wcard(dptr_num, strdup(mask));
+			dptr_set_wcard(dptr_num, SMB_STRDUP(mask));
 			dptr_set_attr(dptr_num, dirtype);
 		} else {
 			dirtype = dptr_attr(dptr_num);
@@ -4884,7 +4884,7 @@
 		if(fsp->wbmpx_ptr != NULL)
 			wbms = fsp->wbmpx_ptr; /* Use an existing struct */
 		else
-			wbms = (write_bmpx_struct *)malloc(sizeof(write_bmpx_struct));
+			wbms = SMB_MALLOC_P(write_bmpx_struct);
 		if(!wbms) {
 			DEBUG(0,("Out of memory in reply_readmpx\n"));
 			END_PROFILE(SMBwriteBmpx);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/sec_ctx.c samba-3.0.9/source/smbd/sec_ctx.c
--- samba-3.0.9-orig/source/smbd/sec_ctx.c	2004-11-15 21:03:15.000000000 -0600
+++ samba-3.0.9/source/smbd/sec_ctx.c	2004-12-09 09:00:27.088643376 -0600
@@ -154,7 +154,7 @@
 		goto fail;
 	}
 
-	if((groups = (gid_t *)malloc(sizeof(gid_t)*(ngroups+1))) == NULL) {
+	if((groups = SMB_MALLOC_ARRAY(gid_t, ngroups+1)) == NULL) {
 		DEBUG(0,("setup_groups malloc fail !\n"));
 		goto fail;
 	}
@@ -260,7 +260,7 @@
 	ctx_p->ngroups = sys_getgroups(0, NULL);
 
 	if (ctx_p->ngroups != 0) {
-		if (!(ctx_p->groups = malloc(ctx_p->ngroups * sizeof(gid_t)))) {
+		if (!(ctx_p->groups = SMB_MALLOC_ARRAY(gid_t, ctx_p->ngroups))) {
 			DEBUG(0, ("Out of memory in push_sec_ctx()\n"));
 			delete_nt_token(&ctx_p->token);
 			return False;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/session.c samba-3.0.9/source/smbd/session.c
--- samba-3.0.9-orig/source/smbd/session.c	2004-11-15 21:03:15.000000000 -0600
+++ samba-3.0.9/source/smbd/session.c	2004-12-09 09:00:27.087643625 -0600
@@ -151,7 +151,7 @@
 			       sessionid.id_str, sessionid.id_num);
 	}
 
-	vuser->session_keystr = strdup(keystr);
+	vuser->session_keystr = SMB_STRDUP(keystr);
 	if (!vuser->session_keystr) {
 		DEBUG(0, ("session_claim:  strdup() failed for session_keystr\n"));
 		return False;
@@ -221,8 +221,8 @@
 	const struct sessionid *current = (const struct sessionid *) dbuf.dptr;
 
 	sesslist->count += 1;
-	sesslist->sessions = REALLOC(sesslist->sessions, sesslist->count * 
-				      sizeof(struct sessionid));
+	sesslist->sessions = SMB_REALLOC_ARRAY(sesslist->sessions, struct sessionid,
+					sesslist->count);
 
 	memcpy(&sesslist->sessions[sesslist->count - 1], current, 
 	       sizeof(struct sessionid));
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/statcache.c samba-3.0.9/source/smbd/statcache.c
--- samba-3.0.9-orig/source/smbd/statcache.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/statcache.c	2004-12-09 09:00:27.058650828 -0600
@@ -76,7 +76,7 @@
 	 * translated path.
 	 */
 
-	translated_path = strdup(orig_translated_path);
+	translated_path = SMB_STRDUP(orig_translated_path);
 	if (!translated_path)
 		return;
 
@@ -88,7 +88,7 @@
 	}
 
 	if(case_sensitive) {
-		original_path = strdup(full_orig_name);
+		original_path = SMB_STRDUP(full_orig_name);
 	} else {
 		original_path = strdup_upper(full_orig_name);
 	}
@@ -179,7 +179,7 @@
 		return False;
 
 	if (conn->case_sensitive) {
-		chk_name = strdup(name);
+		chk_name = SMB_STRDUP(name);
 		if (!chk_name) {
 			DEBUG(0, ("stat_cache_lookup: strdup failed!\n"));
 			return False;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/trans2.c samba-3.0.9/source/smbd/trans2.c
--- samba-3.0.9-orig/source/smbd/trans2.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/trans2.c	2004-12-09 09:00:27.081645115 -0600
@@ -115,7 +115,7 @@
 
  again:
 
-	val = talloc_realloc(mem_ctx, val, attr_size);
+	val = TALLOC_REALLOC_ARRAY(mem_ctx, val, char, attr_size);
 	if (!val) {
 		return False;
 	}
@@ -169,8 +169,8 @@
 		return NULL;
 	}
 
-	for (i = 0, ea_namelist = talloc(mem_ctx, ea_namelist_size); i < 6;
-			ea_namelist = talloc_realloc(mem_ctx, ea_namelist, ea_namelist_size), i++) {
+	for (i = 0, ea_namelist = TALLOC(mem_ctx, ea_namelist_size); i < 6;
+			ea_namelist = TALLOC_REALLOC_ARRAY(mem_ctx, ea_namelist, char, ea_namelist_size), i++) {
 		if (fsp && fsp->fd != -1) {
 			sizeret = SMB_VFS_FLISTXATTR(fsp, fsp->fd, ea_namelist, ea_namelist_size);
 		} else {
@@ -196,7 +196,7 @@
 			if (strnequal(p, "system.", 7) || samba_private_attr_name(p))
 				continue;
 		
-			listp = talloc(mem_ctx, sizeof(struct ea_list));
+			listp = TALLOC_P(mem_ctx, struct ea_list);
 			if (!listp)
 				return NULL;
 
@@ -671,7 +671,7 @@
 	}
 
 	/* Realloc the size of parameters and data we will return */
-	params = Realloc(*pparams, 28);
+	params = SMB_REALLOC(*pparams, 28);
 	if( params == NULL )
 		return(ERROR_DOS(ERRDOS,ERRnomem));
 	*pparams = params;
@@ -1411,7 +1411,7 @@
 
 	DEBUG(5,("dir=%s, mask = %s\n",directory, mask));
 
-	pdata = Realloc(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
+	pdata = SMB_REALLOC(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
 	if( pdata == NULL )
 		return(ERROR_DOS(ERRDOS,ERRnomem));
 
@@ -1419,7 +1419,7 @@
 	memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
 
 	/* Realloc the params space */
-	params = Realloc(*pparams, 10);
+	params = SMB_REALLOC(*pparams, 10);
 	if (params == NULL)
 		return ERROR_DOS(ERRDOS,ERRnomem);
 	*pparams = params;
@@ -1431,7 +1431,7 @@
 	/* Save the wildcard match and attribs we are using on this directory - 
 		needed as lanman2 assumes these are being saved between calls */
 
-	if(!(wcard = strdup(mask))) {
+	if(!(wcard = SMB_STRDUP(mask))) {
 		dptr_close(&dptr_num);
 		return ERROR_DOS(ERRDOS,ERRnomem);
 	}
@@ -1609,7 +1609,7 @@
 			return ERROR_DOS(ERRDOS,ERRunknownlevel);
 	}
 
-	pdata = Realloc( *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
+	pdata = SMB_REALLOC( *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
 	if(pdata == NULL)
 		return ERROR_DOS(ERRDOS,ERRnomem);
 
@@ -1617,7 +1617,7 @@
 	memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
 
 	/* Realloc the params space */
-	params = Realloc(*pparams, 6*SIZEOFWORD);
+	params = SMB_REALLOC(*pparams, 6*SIZEOFWORD);
 	if( params == NULL )
 		return ERROR_DOS(ERRDOS,ERRnomem);
 
@@ -1829,7 +1829,7 @@
 		return ERROR_DOS(ERRSRV,ERRinvdevice);
 	}
 
-	pdata = Realloc(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
+	pdata = SMB_REALLOC(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
 	if ( pdata == NULL )
 		return ERROR_DOS(ERRDOS,ERRnomem);
 
@@ -2395,13 +2395,13 @@
 	if (mode & aDIR)
 		file_size = 0;
 
-	params = Realloc(*pparams,2);
+	params = SMB_REALLOC(*pparams,2);
 	if (params == NULL)
 	  return ERROR_DOS(ERRDOS,ERRnomem);
 	*pparams = params;
 	memset((char *)params,'\0',2);
 	data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
-	pdata = Realloc(*ppdata, data_size); 
+	pdata = SMB_REALLOC(*ppdata, data_size); 
 	if ( pdata == NULL )
 		return ERROR_DOS(ERRDOS,ERRnomem);
 	*ppdata = pdata;
@@ -3096,7 +3096,7 @@
 		tran_call,fname, fsp ? fsp->fnum : -1, info_level,total_data));
 
 	/* Realloc the parameter and data sizes */
-	params = Realloc(*pparams,2);
+	params = SMB_REALLOC(*pparams,2);
 	if(params == NULL)
 		return ERROR_DOS(ERRDOS,ERRnomem);
 	*pparams = params;
@@ -3770,7 +3770,7 @@
 	}
 
 	/* Realloc the parameter and data sizes */
-	params = Realloc(*pparams,2);
+	params = SMB_REALLOC(*pparams,2);
 	if(params == NULL)
 		return ERROR_DOS(ERRDOS,ERRnomem);
 	*pparams = params;
@@ -3810,7 +3810,7 @@
 	}
 
 	/* Realloc the parameter and data sizes */
-	params = Realloc(*pparams,6);
+	params = SMB_REALLOC(*pparams,6);
 	if(params == NULL) 
 		return ERROR_DOS(ERRDOS,ERRnomem);
 	*pparams = params;
@@ -3843,7 +3843,7 @@
 	DEBUG(3,("call_trans2findnotifynext\n"));
 
 	/* Realloc the parameter and data sizes */
-	params = Realloc(*pparams,4);
+	params = SMB_REALLOC(*pparams,4);
 	if(params == NULL)
 		return ERROR_DOS(ERRDOS,ERRnomem);
 	*pparams = params;
@@ -3910,7 +3910,7 @@
 
 	if ((SVAL(inbuf,(smb_setup+4)) == LMCAT_SPL) &&
 			(SVAL(inbuf,(smb_setup+6)) == LMFUNC_GETJOBID)) {
-		pdata = Realloc(*ppdata, 32);
+		pdata = SMB_REALLOC(*ppdata, 32);
 		if(pdata == NULL)
 			return ERROR_DOS(ERRDOS,ERRnomem);
 		*ppdata = pdata;
@@ -4061,9 +4061,9 @@
     
 	/* Allocate the space for the maximum needed parameters and data */
 	if (total_params > 0)
-		params = (char *)malloc(total_params);
+		params = (char *)SMB_MALLOC(total_params);
 	if (total_data > 0)
-		data = (char *)malloc(total_data);
+		data = (char *)SMB_MALLOC(total_data);
   
 	if ((total_params && !params)  || (total_data && !data)) {
 		DEBUG(2,("Out of memory in reply_trans2\n"));
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/smbd/vfs.c samba-3.0.9/source/smbd/vfs.c
--- samba-3.0.9-orig/source/smbd/vfs.c	2004-11-15 21:03:14.000000000 -0600
+++ samba-3.0.9/source/smbd/vfs.c	2004-12-09 09:00:27.056651325 -0600
@@ -185,7 +185,7 @@
 		return NT_STATUS_OBJECT_NAME_COLLISION;
 	}
 
-	entry = smb_xmalloc(sizeof(struct vfs_init_function_entry));
+	entry = SMB_XMALLOC_P(struct vfs_init_function_entry);
 	entry->name = smb_xstrdup(name);
 	entry->vfs_op_tuples = vfs_op_tuples;
 
@@ -258,7 +258,7 @@
 		return False;
 	}
 
-	handle = (vfs_handle_struct *)talloc_zero(conn->mem_ctx,sizeof(vfs_handle_struct));
+	handle = TALLOC_ZERO_P(conn->mem_ctx,vfs_handle_struct);
 	if (!handle) {
 		DEBUG(0,("talloc_zero() failed!\n"));
 		SAFE_FREE(module_name);
@@ -681,7 +681,7 @@
 	if (element == 0)
 		return;
 
-	p = (char *)malloc(elsize);
+	p = (char *)SMB_MALLOC(elsize);
 
 	if (!p) {
 		DEBUG(5,("array_promote: malloc fail\n"));
@@ -876,7 +876,7 @@
 				pstrcat(tmp_fname, last_component);
 #ifdef REALPATH_TAKES_NULL
 				SAFE_FREE(resolved_name);
-				resolved_name = strdup(tmp_fname);
+				resolved_name = SMB_STRDUP(tmp_fname);
 				if (!resolved_name) {
 					DEBUG(0,("reduce_name: malloc fail for %s\n", tmp_fname));
 					errno = saved_errno;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/tdb/tdbback.c samba-3.0.9/source/tdb/tdbback.c
--- samba-3.0.9-orig/source/tdb/tdbback.c	2004-11-15 21:03:34.000000000 -0600
+++ samba-3.0.9/source/tdb/tdbback.c	2004-12-09 09:00:27.601515957 -0600
@@ -40,6 +40,19 @@
 
 #else
 #include "includes.h"
+
+#ifdef malloc
+#undef malloc
+#endif
+                                                                                                                 
+#ifdef realloc
+#undef realloc
+#endif
+                                                                                                                 
+#ifdef calloc
+#undef calloc
+#endif
+
 #endif
 
 #include "tdb.h"
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/tdb/tdb.c samba-3.0.9/source/tdb/tdb.c
--- samba-3.0.9-orig/source/tdb/tdb.c	2004-11-15 21:03:34.000000000 -0600
+++ samba-3.0.9/source/tdb/tdb.c	2004-12-09 09:00:27.599516453 -0600
@@ -65,6 +65,30 @@
 #include "spinlock.h"
 #else
 #include "includes.h"
+
+#if defined(PARANOID_MALLOC_CHECKER)
+#ifdef malloc
+#undef malloc
+#endif
+
+#ifdef realloc
+#undef realloc
+#endif
+
+#ifdef calloc
+#undef calloc
+#endif
+
+#ifdef strdup
+#undef strdup
+#endif
+
+#ifdef strndup
+#undef strndup
+#endif
+
+#endif
+
 #endif
 
 #define TDB_MAGIC_FOOD "TDB file\n"
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/tdb/tdbutil.c samba-3.0.9/source/tdb/tdbutil.c
--- samba-3.0.9-orig/source/tdb/tdbutil.c	2004-11-15 21:03:34.000000000 -0600
+++ samba-3.0.9/source/tdb/tdbutil.c	2004-12-09 09:00:27.594517695 -0600
@@ -554,7 +554,7 @@
 			len += *i;
 			if (bufsize < len)
 				goto no_space;
-			*b = (char *)malloc(*i);
+			*b = (char *)SMB_MALLOC(*i);
 			if (! *b)
 				goto no_space;
 			memcpy(*b, buf+4, *i);
@@ -778,7 +778,7 @@
 	
 	for (key = tdb_firstkey(tdb); key.dptr; key = next) {
 		/* duplicate key string to ensure null-termination */
-		char *key_str = (char*) strndup(key.dptr, key.dsize);
+		char *key_str = (char*) SMB_STRNDUP(key.dptr, key.dsize);
 		if (!key_str) {
 			DEBUG(0, ("tdb_search_keys: strndup() failed!\n"));
 			smb_panic("strndup failed!\n");
@@ -790,7 +790,7 @@
 
 		/* do the pattern checking */
 		if (fnmatch(pattern, key_str, 0) == 0) {
-			rec = (TDB_LIST_NODE*) malloc(sizeof(*rec));
+			rec = SMB_MALLOC_P(TDB_LIST_NODE);
 			ZERO_STRUCTP(rec);
 
 			rec->node_key = key;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/net_ads.c samba-3.0.9/source/utils/net_ads.c
--- samba-3.0.9-orig/source/utils/net_ads.c	2004-11-15 21:03:33.000000000 -0600
+++ samba-3.0.9/source/utils/net_ads.c	2004-12-09 09:00:27.570523656 -0600
@@ -259,10 +259,10 @@
 	if (!values) /* must be new field, indicate string field */
 		return True;
 	if (StrCaseCmp(field, "sAMAccountName") == 0) {
-		disp_fields[0] = strdup((char *) values[0]);
+		disp_fields[0] = SMB_STRDUP((char *) values[0]);
 	}
 	if (StrCaseCmp(field, "description") == 0)
-		disp_fields[1] = strdup((char *) values[0]);
+		disp_fields[1] = SMB_STRDUP((char *) values[0]);
 	return True;
 }
 
@@ -718,7 +718,7 @@
 	}
 
 	tmp_password = generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
-	password = strdup(tmp_password);
+	password = SMB_STRDUP(tmp_password);
 
 	if (!(ads = ads_startup())) {
 		return -1;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/net.c samba-3.0.9/source/utils/net.c
--- samba-3.0.9-orig/source/utils/net.c	2004-11-15 21:03:33.000000000 -0600
+++ samba-3.0.9/source/utils/net.c	2004-12-09 09:00:27.573522911 -0600
@@ -144,7 +144,7 @@
 	if (!opt_password && !opt_machine_pass) {
 		char *pass = getpass("Password:");
 		if (pass) {
-			opt_password = strdup(pass);
+			opt_password = SMB_STRDUP(pass);
 		}
 	}
 	
@@ -221,11 +221,11 @@
 NTSTATUS connect_pipe(struct cli_state **cli_dst, int pipe_num, BOOL *got_pipe)
 {
 	NTSTATUS nt_status;
-	char *server_name = strdup("127.0.0.1");
+	char *server_name = SMB_STRDUP("127.0.0.1");
 	struct cli_state *cli_tmp = NULL;
 
 	if (opt_destination)
-		server_name = strdup(opt_destination);
+		server_name = SMB_STRDUP(opt_destination);
 
 	/* make a connection to a named pipe */
 	nt_status = connect_to_ipc(&cli_tmp, NULL, server_name);
@@ -270,13 +270,13 @@
 {
 
 	if (opt_host) {
-		*server_name = strdup(opt_host);
+		*server_name = SMB_STRDUP(opt_host);
 	}		
 
 	if (opt_have_ip) {
 		*server_ip = opt_dest_ip;
 		if (!*server_name) {
-			*server_name = strdup(inet_ntoa(opt_dest_ip));
+			*server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip));
 		}
 	} else if (*server_name) {
 		/* resolve the IP address */
@@ -296,7 +296,7 @@
 			if ( !name_status_find(opt_target_workgroup, 0x1b, 0x20, pdc_ip, dc_name) )
 				return False;
 				
-			*server_name = strdup(dc_name);
+			*server_name = SMB_STRDUP(dc_name);
 			*server_ip = pdc_ip;
 		}
 		
@@ -309,7 +309,7 @@
 		} else {
 			*server_ip = msbrow_ip;
 		}
-		*server_name = strdup(inet_ntoa(opt_dest_ip));
+		*server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip));
 	} else if (flags & NET_FLAGS_MASTER) {
 		struct in_addr brow_ips;
 		if (!resolve_name(opt_target_workgroup, &brow_ips, 0x1D))  {
@@ -319,11 +319,11 @@
 		} else {
 			*server_ip = brow_ips;
 		}
-		*server_name = strdup(inet_ntoa(opt_dest_ip));
+		*server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip));
 	} else if (!(flags & NET_FLAGS_LOCALHOST_DEFAULT_INSANE)) {
 		extern struct in_addr loopback_ip;
 		*server_ip = loopback_ip;
-		*server_name = strdup("127.0.0.1");
+		*server_name = SMB_STRDUP("127.0.0.1");
 	}
 
 	if (!server_name || !*server_name) {
@@ -786,7 +786,7 @@
 			break;
 		case 'U':
 			opt_user_specified = True;
-			opt_user_name = strdup(opt_user_name);
+			opt_user_name = SMB_STRDUP(opt_user_name);
 			p = strchr(opt_user_name,'%');
 			if (p) {
 				*p = 0;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/net_cache.c samba-3.0.9/source/utils/net_cache.c
--- samba-3.0.9-orig/source/utils/net_cache.c	2004-11-15 21:03:32.000000000 -0600
+++ samba-3.0.9/source/utils/net_cache.c	2004-12-09 09:00:27.540531108 -0600
@@ -101,7 +101,7 @@
 	/* number detection */
 	len = (sign) ? strlen(&timeout_str[number_begin]) : len;
 	number_end = (unit) ? len - 1 : len;
-	number = strndup(&timeout_str[number_begin], number_end);
+	number = SMB_STRNDUP(&timeout_str[number_begin], number_end);
 	
 	/* calculate actual timeout value */
 	timeout = (time_t)atoi(number);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/net_idmap.c samba-3.0.9/source/utils/net_idmap.c
--- samba-3.0.9-orig/source/utils/net_idmap.c	2004-11-15 21:03:32.000000000 -0600
+++ samba-3.0.9/source/utils/net_idmap.c	2004-12-09 09:00:27.565524898 -0600
@@ -126,7 +126,7 @@
 		return NT_STATUS_UNSUCCESSFUL;
 	}
 
-	tdbfile = strdup(lock_path("winbindd_idmap.tdb"));
+	tdbfile = SMB_STRDUP(lock_path("winbindd_idmap.tdb"));
 	if (!tdbfile) {
 		DEBUG(0, ("idmap_init: out of memory!\n"));
 		return NT_STATUS_NO_MEMORY;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/net_rap.c samba-3.0.9/source/utils/net_rap.c
--- samba-3.0.9-orig/source/utils/net_rap.c	2004-11-15 21:03:32.000000000 -0600
+++ samba-3.0.9/source/utils/net_rap.c	2004-12-09 09:00:27.551528376 -0600
@@ -198,7 +198,7 @@
 	if (!(cli = net_make_ipc_connection(0))) 
                 return -1;
 
-	sharename = strdup(argv[0]);
+	sharename = SMB_STRDUP(argv[0]);
 	p = strchr(sharename, '=');
 	*p = 0;
 	strlcpy(sinfo.share_name, sharename, sizeof(sinfo.share_name));
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/net_rpc.c samba-3.0.9/source/utils/net_rpc.c
--- samba-3.0.9-orig/source/utils/net_rpc.c	2004-11-15 21:03:33.000000000 -0600
+++ samba-3.0.9/source/utils/net_rpc.c	2004-12-09 09:00:27.584520179 -0600
@@ -884,7 +884,7 @@
 
 	/* Look up rids */
 
-	rids = (uint32 *)talloc(mem_ctx, sizeof(uint32) * num_rids);
+	rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids);
 
 	for (i = 0; i < num_rids; i++)
                 rids[i] = user_gids[i].g_rid;
@@ -2805,7 +2805,7 @@
 	pstring mask;
 	char *dst = NULL;
 
-	dst = strdup(opt_destination?opt_destination:"127.0.0.1");
+	dst = SMB_STRDUP(opt_destination?opt_destination:"127.0.0.1");
 
 	init_enum_hnd(&hnd, 0);
 
@@ -2989,7 +2989,7 @@
 static void push_alias(TALLOC_CTX *mem_ctx, struct full_alias *alias)
 {
 	if (server_aliases == NULL)
-		server_aliases = malloc(100 * sizeof(struct full_alias));
+		server_aliases = SMB_MALLOC_ARRAY(struct full_alias, 100);
 
 	server_aliases[num_server_aliases] = *alias;
 	num_server_aliases += 1;
@@ -3053,8 +3053,7 @@
 			alias.members = NULL;
 
 			if (alias.num_members > 0) {
-				alias.members = malloc(alias.num_members *
-						       sizeof(DOM_SID));
+				alias.members = SMB_MALLOC_ARRAY(DOM_SID, alias.num_members);
 
 				for (j = 0; j < alias.num_members; j++)
 					sid_copy(&alias.members[j],
@@ -3183,7 +3182,7 @@
 
 	token->num_sids = 4;
 
-	token->user_sids = malloc(4 * sizeof(DOM_SID));
+	token->user_sids = SMB_MALLOC_ARRAY(DOM_SID, 4);
 
 	token->user_sids[0] = *user_sid;
 	sid_copy(&token->user_sids[1], &global_sid_World);
@@ -3212,8 +3211,7 @@
 	if (is_sid_in_token(token, sid))
 		return;
 
-	token->user_sids = Realloc(token->user_sids,
-				   (token->num_sids+1) * sizeof(DOM_SID));
+	token->user_sids = SMB_REALLOC_ARRAY(token->user_sids, DOM_SID, token->num_sids+1);
 
 	sid_copy(&token->user_sids[token->num_sids], sid);
 
@@ -3392,7 +3390,7 @@
 		*num_tokens += 1;
 	}
 
-	result = malloc(*num_tokens * sizeof(struct user_token));
+	result = SMB_MALLOC_ARRAY(struct user_token, *num_tokens);
 
 	if (result == NULL) {
 		DEBUG(1, ("Could not malloc sid array\n"));
@@ -3467,9 +3465,7 @@
 		/* And a new user... */
 
 		*num_tokens += 1;
-		*tokens = Realloc(*tokens,
-				  *num_tokens *
-				  sizeof(struct user_token));
+		*tokens = SMB_REALLOC_ARRAY(*tokens, struct user_token, *num_tokens);
 		if (*tokens == NULL) {
 			DEBUG(0, ("Could not realloc tokens\n"));
 			return False;
@@ -3587,9 +3583,8 @@
 		return;
 
 	share_list->num_shares += 1;
-	share_list->shares = Realloc(share_list->shares,
-				     share_list->num_shares * sizeof(char *));
-	share_list->shares[share_list->num_shares-1] = strdup(name);
+	share_list->shares = SMB_REALLOC_ARRAY(share_list->shares, char *, share_list->num_shares);
+	share_list->shares[share_list->num_shares-1] = SMB_STRDUP(name);
 }
 
 static void rpc_share_userlist_usage(void)
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/net_rpc_join.c samba-3.0.9/source/utils/net_rpc_join.c
--- samba-3.0.9-orig/source/utils/net_rpc_join.c	2004-11-15 21:03:32.000000000 -0600
+++ samba-3.0.9/source/utils/net_rpc_join.c	2004-12-09 09:00:27.539531356 -0600
@@ -258,7 +258,7 @@
 	{ 
 		char *str;
 		str = generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
-		clear_trust_password = strdup(str);
+		clear_trust_password = SMB_STRDUP(str);
 		E_md4hash(clear_trust_password, md4_trust_password);
 	}
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/net_rpc_printer.c samba-3.0.9/source/utils/net_rpc_printer.c
--- samba-3.0.9-orig/source/utils/net_rpc_printer.c	2004-11-15 21:03:32.000000000 -0600
+++ samba-3.0.9/source/utils/net_rpc_printer.c	2004-12-09 09:00:27.564525147 -0600
@@ -501,7 +501,7 @@
 		}
 
 		/* allocate memory */
-		if (!(data = (char *)malloc(read_size))) {
+		if (!(data = (char *)SMB_MALLOC(read_size))) {
 			d_printf("malloc fail for size %d\n", read_size);
 			nt_status = NT_STATUS_NO_MEMORY;
 			goto out;
@@ -1153,7 +1153,7 @@
 
 
 	/* argument given, get a single printer by name */
-	sharename = strdup(argv[0]);
+	sharename = SMB_STRDUP(argv[0]);
 
 	if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename,
 			MAXIMUM_ALLOWED_ACCESS,	cli->user_name, &hnd)) 
@@ -2298,7 +2298,7 @@
 		}
 
 		/* copy devmode (info level 2) */
-		ctr_dst.printers_2->devmode = talloc_memdup(mem_ctx, 
+		ctr_dst.printers_2->devmode = TALLOC_MEMDUP(mem_ctx, 
 			ctr_enum.printers_2[i].devmode, sizeof(DEVICEMODE));
 
 		/* do not copy security descriptor (we have another command for that) */
@@ -2460,7 +2460,7 @@
 
 					value.type = REG_SZ;
 					value.size = data.uni_str_len * 2;
-					value.data_p = talloc_memdup(mem_ctx, data.buffer, value.size);
+					value.data_p = TALLOC_MEMDUP(mem_ctx, data.buffer, value.size);
 
 					if (opt_verbose) 
 						display_reg_value(subkey, value);
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/net_rpc_samsync.c samba-3.0.9/source/utils/net_rpc_samsync.c
--- samba-3.0.9-orig/source/utils/net_rpc_samsync.c	2004-11-15 21:03:33.000000000 -0600
+++ samba-3.0.9/source/utils/net_rpc_samsync.c	2004-12-09 09:00:27.575522414 -0600
@@ -595,7 +595,7 @@
 		return NT_STATUS_NO_MEMORY;
 	}
 
-	nt_members = talloc_zero(t, sizeof(char *) * delta->num_members);
+	nt_members = TALLOC_ZERO_ARRAY(t, char *, delta->num_members);
 
 	for (i=0; i<delta->num_members; i++) {
 		NTSTATUS nt_status;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/net_status.c samba-3.0.9/source/utils/net_status.c
--- samba-3.0.9-orig/source/utils/net_status.c	2004-11-15 21:03:33.000000000 -0600
+++ samba-3.0.9/source/utils/net_status.c	2004-12-09 09:00:27.577521918 -0600
@@ -129,8 +129,7 @@
 		return 0;
 
 	ids->num_entries += 1;
-	ids->entries = Realloc(ids->entries,
-			       sizeof(struct sessionid) * ids->num_entries);
+	ids->entries = SMB_REALLOC_ARRAY(ids->entries, struct sessionid, ids->num_entries);
 	ids->entries[ids->num_entries-1] = sessionid;
 
 	return 0;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/ntlm_auth.c samba-3.0.9/source/utils/ntlm_auth.c
--- samba-3.0.9-orig/source/utils/ntlm_auth.c	2004-11-15 21:03:32.000000000 -0600
+++ samba-3.0.9/source/utils/ntlm_auth.c	2004-12-09 09:00:27.560526140 -0600
@@ -238,7 +238,7 @@
 		return False;
 	}
 
-	require_membership_of_sid = strdup(response.data.sid.sid);
+	require_membership_of_sid = SMB_STRDUP(response.data.sid.sid);
 
 	if (require_membership_of_sid)
 		return True;
@@ -378,7 +378,7 @@
 	}
 
 	if (flags & WBFLAG_PAM_UNIX_NAME) {
-		*unix_name = strdup((char *)response.extra_data);
+		*unix_name = SMB_STRDUP((char *)response.extra_data);
 		if (!*unix_name) {
 			free_response(&response);
 			return NT_STATUS_NO_MEMORY;
@@ -552,7 +552,7 @@
 	if ((strncmp(buf, "PW ", 3) == 0)) {
 		/* The calling application wants us to use a local password (rather than winbindd) */
 
-		opt_password = strndup((const char *)request.data, request.length);
+		opt_password = SMB_STRNDUP((const char *)request.data, request.length);
 
 		if (opt_password == NULL) {
 			DEBUG(1, ("Out of memory\n"));
@@ -634,7 +634,7 @@
 	if (strncmp(buf, "PW ", 3) == 0) {
 		/* We asked for a password and obviously got it :-) */
 
-		opt_password = strndup((const char *)request.data, request.length);
+		opt_password = SMB_STRNDUP((const char *)request.data, request.length);
 
 		if (opt_password == NULL) {
 			DEBUG(1, ("Out of memory\n"));
@@ -753,7 +753,7 @@
 
 	/* Server negTokenInit (mech offerings) */
 	spnego.type = SPNEGO_NEG_TOKEN_INIT;
-	spnego.negTokenInit.mechTypes = smb_xmalloc(sizeof(char *) * 3);
+	spnego.negTokenInit.mechTypes = SMB_XMALLOC_ARRAY(char *, 3);
 #ifdef HAVE_KRB5
 	spnego.negTokenInit.mechTypes[0] = smb_xstrdup(OID_KERBEROS5_OLD);
 	spnego.negTokenInit.mechTypes[1] = smb_xstrdup(OID_NTLMSSP);
@@ -883,7 +883,7 @@
 				  request.negTokenInit.mechToken.length);
 
 			response.type = SPNEGO_NEG_TOKEN_TARG;
-			response.negTokenTarg.supportedMech = strdup(OID_NTLMSSP);
+			response.negTokenTarg.supportedMech = SMB_STRDUP(OID_NTLMSSP);
 			response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
 
 			status = ntlmssp_update(ntlmssp_state,
@@ -906,7 +906,7 @@
 			}
 
 			response.type = SPNEGO_NEG_TOKEN_TARG;
-			response.negTokenTarg.supportedMech = strdup(OID_KERBEROS5_OLD);
+			response.negTokenTarg.supportedMech = SMB_STRDUP(OID_KERBEROS5_OLD);
 			response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
 			response.negTokenTarg.responseToken = data_blob(NULL, 0);
 
@@ -930,8 +930,8 @@
 				}
 
 				*domain++ = '\0';
-				domain = strdup(domain);
-				user = strdup(principal);
+				domain = SMB_STRDUP(domain);
+				user = SMB_STRDUP(principal);
 
 				data_blob_free(&ap_rep);
 				data_blob_free(&auth_data);
@@ -964,12 +964,12 @@
 					       &response.negTokenTarg.responseToken);
 
 		response.type = SPNEGO_NEG_TOKEN_TARG;
-		response.negTokenTarg.supportedMech = strdup(OID_NTLMSSP);
+		response.negTokenTarg.supportedMech = SMB_STRDUP(OID_NTLMSSP);
 		response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
 
 		if (NT_STATUS_IS_OK(status)) {
-			user = strdup(ntlmssp_state->user);
-			domain = strdup(ntlmssp_state->domain);
+			user = SMB_STRDUP(ntlmssp_state->user);
+			domain = SMB_STRDUP(ntlmssp_state->domain);
 			ntlmssp_end(&ntlmssp_state);
 		}
 	}
@@ -1155,7 +1155,7 @@
 		return False;
 	}
 
-	principal = malloc(spnego.negTokenInit.mechListMIC.length+1);
+	principal = SMB_MALLOC(spnego.negTokenInit.mechListMIC.length+1);
 
 	if (principal == NULL) {
 		DEBUG(1, ("Could not malloc principal\n"));
@@ -1266,7 +1266,7 @@
 
 		/* We asked for a password and obviously got it :-) */
 
-		opt_password = strndup((const char *)request.data, request.length);
+		opt_password = SMB_STRNDUP((const char *)request.data, request.length);
 		
 		if (opt_password == NULL) {
 			DEBUG(1, ("Out of memory\n"));
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/pdbedit.c samba-3.0.9/source/utils/pdbedit.c
--- samba-3.0.9-orig/source/utils/pdbedit.c	2004-11-15 21:03:33.000000000 -0600
+++ samba-3.0.9/source/utils/pdbedit.c	2004-12-09 09:00:27.567524401 -0600
@@ -429,10 +429,10 @@
 	}
 
 	staticpass = getpass("new password:");
-	password1 = strdup(staticpass);
+	password1 = SMB_STRDUP(staticpass);
 	memset(staticpass, 0, strlen(staticpass));
 	staticpass = getpass("retype new password:");
-	password2 = strdup(staticpass);
+	password2 = SMB_STRDUP(staticpass);
 	memset(staticpass, 0, strlen(staticpass));
 	if (strcmp (password1, password2)) {
 		fprintf (stderr, "Passwords does not match!\n");
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/smbcacls.c samba-3.0.9/source/utils/smbcacls.c
--- samba-3.0.9-orig/source/utils/smbcacls.c	2004-11-15 21:03:32.000000000 -0600
+++ samba-3.0.9/source/utils/smbcacls.c	2004-12-09 09:00:27.542530611 -0600
@@ -325,7 +325,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);
@@ -353,7 +353,7 @@
 		}
 
 		if (strncmp(tok,"OWNER:", 6) == 0) {
-			owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
+			owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
 			if (!owner_sid ||
 			    !StringToSid(owner_sid, tok+6)) {
 				printf("Failed to parse owner sid\n");
@@ -363,7 +363,7 @@
 		}
 
 		if (strncmp(tok,"GROUP:", 6) == 0) {
-			grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
+			grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
 			if (!grp_sid ||
 			    !StringToSid(grp_sid, tok+6)) {
 				printf("Failed to parse group sid\n");
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/utils/smbtree.c samba-3.0.9/source/utils/smbtree.c
--- samba-3.0.9-orig/source/utils/smbtree.c	2004-11-15 21:03:32.000000000 -0600
+++ samba-3.0.9/source/utils/smbtree.c	2004-12-09 09:00:27.538531605 -0600
@@ -51,7 +51,7 @@
         struct name_list **name_list = (struct name_list **)state;
         struct name_list *new_name;
 
-        new_name = (struct name_list *)malloc(sizeof(struct name_list));
+        new_name = SMB_MALLOC_P(struct name_list);
 
         if (!new_name)
                 return;
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/web/cgi.c samba-3.0.9/source/web/cgi.c
--- samba-3.0.9-orig/source/web/cgi.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/web/cgi.c	2004-12-09 09:00:27.385569607 -0600
@@ -59,7 +59,7 @@
 			char *ret2;
 			if (len == 0) len = 1024;
 			else len *= 2;
-			ret2 = (char *)Realloc(ret, len);
+			ret2 = (char *)SMB_REALLOC(ret, len);
 			if (!ret2) return ret;
 			ret = ret2;
 		}
@@ -135,8 +135,8 @@
 			
 			*p = 0;
 			
-			variables[num_variables].name = strdup(line);
-			variables[num_variables].value = strdup(p+1);
+			variables[num_variables].name = SMB_STRDUP(line);
+			variables[num_variables].value = SMB_STRDUP(p+1);
 
 			SAFE_FREE(line);
 			
@@ -170,8 +170,8 @@
 			
 			*p = 0;
 			
-			variables[num_variables].name = strdup(tok);
-			variables[num_variables].value = strdup(p+1);
+			variables[num_variables].name = SMB_STRDUP(tok);
+			variables[num_variables].value = SMB_STRDUP(p+1);
 
 			if (!variables[num_variables].name || 
 			    !variables[num_variables].value)
@@ -205,13 +205,13 @@
 			       variables[i].name, -1, 
 			       dest, sizeof(dest), True);
 		free(variables[i].name);
-		variables[i].name = strdup(dest);
+		variables[i].name = SMB_STRDUP(dest);
 
 		convert_string(CH_UTF8, CH_UNIX, 
 			       variables[i].value, -1,
 			       dest, sizeof(dest), True);
 		free(variables[i].value);
-		variables[i].value = strdup(dest);
+		variables[i].value = SMB_STRDUP(dest);
 	}
 }
 
@@ -366,7 +366,7 @@
 			become_user_permanently(pass->pw_uid, pass->pw_gid);
 			
 			/* Save the users name */
-			C_user = strdup(user);
+			C_user = SMB_STRDUP(user);
 			passwd_free(&pass);
 			return True;
 		}
@@ -530,11 +530,11 @@
 		if (line[0] == '\r' || line[0] == '\n') break;
 		if (strnequal(line,"GET ", 4)) {
 			got_request = True;
-			url = strdup(&line[4]);
+			url = SMB_STRDUP(&line[4]);
 		} else if (strnequal(line,"POST ", 5)) {
 			got_request = True;
 			request_post = 1;
-			url = strdup(&line[5]);
+			url = SMB_STRDUP(&line[5]);
 		} else if (strnequal(line,"PUT ", 4)) {
 			got_request = True;
 			cgi_setup_error("400 Bad Request", "",
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/web/neg_lang.c samba-3.0.9/source/web/neg_lang.c
--- samba-3.0.9-orig/source/web/neg_lang.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/web/neg_lang.c	2004-12-09 09:00:27.406564391 -0600
@@ -85,7 +85,7 @@
 		count++;
 		lang_num++;
 	}
-	pl = (struct pri_list *)malloc(sizeof(struct pri_list) * lang_num);
+	pl = SMB_MALLOC_ARRAY(struct pri_list, lang_num);
 	for (i = 0; i < lang_num; i++) {
 		char *pri_code;
 		if ((pri_code=strstr(lang_list[i], ";q="))) {
@@ -95,7 +95,7 @@
 		} else {
 			pl[i].pri = 1;
 		}
-		pl[i].string = strdup(lang_list[i]);
+		pl[i].string = SMB_STRDUP(lang_list[i]);
 	}
 	str_list_free(&lang_list);
 
diff -ruBb --exclude-from=../../../samba-cvs/diff.excludes samba-3.0.9-orig/source/web/statuspage.c samba-3.0.9/source/web/statuspage.c
--- samba-3.0.9-orig/source/web/statuspage.c	2004-11-15 21:03:23.000000000 -0600
+++ samba-3.0.9/source/web/statuspage.c	2004-12-09 09:00:27.384569855 -0600
@@ -61,14 +61,14 @@
 	if (PID_or_Machine) {
 		PIDMAP *newmap;
 
-		if ((newmap = (PIDMAP *) malloc (sizeof (PIDMAP))) == NULL) {
+		if ((newmap = SMB_MALLOC_P(PIDMAP)) == NULL) {
 			/* XXX need error message for this?
 			   if malloc fails, PID is always shown */
 			return;
 		}
 
 		newmap->pid = pid;
-		newmap->machine = strdup (machine);
+		newmap->machine = SMB_STRDUP(machine);
 
 		DLIST_ADD(pidmap, newmap);
 	}