diff options
author | Jeremy Allison <jra@samba.org> | 2004-12-07 18:25:53 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 10:53:32 -0500 |
commit | acf9d61421faa6c0055d57fdee7db300dc5431aa (patch) | |
tree | 5482afecfe9b4a68b9a1f18d541a3109f8143ab7 /source3/lib | |
parent | 3bd3be97dc8a581c0502410453091c195e322766 (diff) | |
download | samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.gz samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.bz2 samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.zip |
r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation
functions so we can funnel through some well known functions. Should help greatly with
malloc checking.
HEAD patch to follow.
Jeremy.
(This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a)
Diffstat (limited to 'source3/lib')
36 files changed, 355 insertions, 192 deletions
diff --git a/source3/lib/access.c b/source3/lib/access.c index f03f5daf33..fcc795d1f2 100644 --- a/source3/lib/access.c +++ b/source3/lib/access.c @@ -86,7 +86,7 @@ static BOOL string_match(const char *tok,const char *s, char *invalid_char) 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 --git a/source3/lib/account_pol.c b/source3/lib/account_pol.c index 9120452e2e..aa59383258 100644 --- a/source3/lib/account_pol.c +++ b/source3/lib/account_pol.c @@ -88,7 +88,7 @@ char *account_policy_names_list(void) len += strlen(account_policy_names[i].string) + 1; } len++; - nl = malloc(len); + nl = SMB_MALLOC(len); if (!nl) { return NULL; } diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index bd857e205a..a5d6380377 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -59,7 +59,7 @@ SORTED_TREE* sorted_tree_init( void *data_p, { 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 @@ SORTED_TREE* sorted_tree_init( void *data_p, 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 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key ) 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 @@ BOOL sorted_tree_add( SORTED_TREE *tree, const char *path, void *data_p ) /* 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 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key ) /* 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 --git a/source3/lib/bitmap.c b/source3/lib/bitmap.c index 3fa20cdd11..a6b52efe09 100644 --- a/source3/lib/bitmap.c +++ b/source3/lib/bitmap.c @@ -30,12 +30,12 @@ struct bitmap *bitmap_allocate(int n) { 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 @@ struct bitmap *bitmap_talloc(TALLOC_CTX *mem_ctx, int n) 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 --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 95e24609cd..e8ceaf39b7 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -538,9 +538,9 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, } 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 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, 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 @@ char *strdup_upper(const char *s) } } - 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 --git a/source3/lib/data_blob.c b/source3/lib/data_blob.c index 83afc591a1..a1c3af2d49 100644 --- a/source3/lib/data_blob.c +++ b/source3/lib/data_blob.c @@ -47,7 +47,7 @@ DATA_BLOB data_blob(const void *p, size_t length) 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 @@ DATA_BLOB data_blob_talloc(TALLOC_CTX *mem_ctx, const void *p, size_t length) } 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 --git a/source3/lib/debug.c b/source3/lib/debug.c index 01aedb4774..b69a35ecd5 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -192,7 +192,7 @@ static char *debug_list_class_names_and_levels(void) 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 @@ static char *debug_list_class_names_and_levels(void) } /* 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 @@ int debug_add_class(const char *classname) /* 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 @@ int debug_add_class(const char *classname) 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 --git a/source3/lib/dprintf.c b/source3/lib/dprintf.c index c62a1f41d1..8ed2fa5d8c 100644 --- a/source3/lib/dprintf.c +++ b/source3/lib/dprintf.c @@ -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 --git a/source3/lib/gencache.c b/source3/lib/gencache.c index 39e727c24f..f2e267c9d4 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -117,9 +117,9 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout) 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 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) = %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 @@ BOOL gencache_del(const char *keystr) 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 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) 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 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time 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 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time 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 --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 66a6e6cd8b..d58165fed0 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -209,15 +209,15 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) 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 --git a/source3/lib/interface.c b/source3/lib/interface.c index adf9ca3438..8cf11b8503 100644 --- a/source3/lib/interface.c +++ b/source3/lib/interface.c @@ -65,7 +65,7 @@ static void add_interface(struct in_addr ip, struct in_addr nmask) return; } - iface = (struct interface *)malloc(sizeof(*iface)); + iface = SMB_MALLOC_P(struct interface); if (!iface) return; ZERO_STRUCTPN(iface); @@ -207,7 +207,7 @@ void load_interfaces(void) 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 --git a/source3/lib/ldap_escape.c b/source3/lib/ldap_escape.c index 9e88b4999c..6c4e8b8c83 100644 --- a/source3/lib/ldap_escape.c +++ b/source3/lib/ldap_escape.c @@ -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 @@ char *escape_ldap_string_alloc(const char *s) 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 --git a/source3/lib/messages.c b/source3/lib/messages.c index ded3ac95bb..dca4b94844 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -190,7 +190,7 @@ static BOOL message_send_pid_internal(pid_t pid, int msg_type, const void *buf, 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 @@ void message_register(int msg_type, { struct dispatch_fns *dfn; - dfn = (struct dispatch_fns *)malloc(sizeof(*dfn)); + dfn = SMB_MALLOC_P(struct dispatch_fns); if (dfn != NULL) { diff --git a/source3/lib/module.c b/source3/lib/module.c index e469b1da42..49121d12ca 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -175,7 +175,7 @@ smb_event_id_t smb_register_idle_event(smb_idle_event_fn *fn, void *data, time_t 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; @@ -257,7 +257,7 @@ smb_event_id_t smb_register_exit_event(smb_exit_event_fn *fn, void *data) 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 --git a/source3/lib/ms_fnmatch.c b/source3/lib/ms_fnmatch.c index 71f3959c24..a0cbfd2ee2 100644 --- a/source3/lib/ms_fnmatch.c +++ b/source3/lib/ms_fnmatch.c @@ -204,7 +204,7 @@ int ms_fnmatch(const char *pattern, const char *string, enum protocol_types prot } 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 --git a/source3/lib/privileges.c b/source3/lib/privileges.c index b9d4df301d..2b8d7613c1 100644 --- a/source3/lib/privileges.c +++ b/source3/lib/privileges.c @@ -75,7 +75,7 @@ NTSTATUS dupalloc_luid_attr(TALLOC_CTX *mem_ctx, LUID_ATTR **new_la, LUID_ATTR * 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 @@ NTSTATUS init_privilege(PRIVILEGE_SET **priv_set) 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 init_priv_with_ctx(TALLOC_CTX *mem_ctx, PRIVILEGE_SET **priv_set) { 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 @@ NTSTATUS add_privilege(PRIVILEGE_SET *priv_set, LUID_ATTR set) /* 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 @@ NTSTATUS remove_privilege(PRIVILEGE_SET *priv_set, LUID_ATTR set) 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 @@ NTSTATUS dup_priv_set(PRIVILEGE_SET *new_priv_set, PRIVILEGE_SET *priv_set) 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 --git a/source3/lib/secace.c b/source3/lib/secace.c index 8c54c97043..e44d9aa940 100644 --- a/source3/lib/secace.c +++ b/source3/lib/secace.c @@ -80,7 +80,7 @@ NTSTATUS sec_ace_add_sid(TALLOC_CTX *ctx, SEC_ACE **new, SEC_ACE *old, unsigned *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 @@ NTSTATUS sec_ace_del_sid(TALLOC_CTX *ctx, SEC_ACE **new, SEC_ACE *old, uint32 *n 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 --git a/source3/lib/secacl.c b/source3/lib/secacl.c index 756685a821..e213e0d9a0 100644 --- a/source3/lib/secacl.c +++ b/source3/lib/secacl.c @@ -32,7 +32,7 @@ SEC_ACL *make_sec_acl(TALLOC_CTX *ctx, uint16 revision, int num_aces, SEC_ACE *a 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 @@ SEC_ACL *make_sec_acl(TALLOC_CTX *ctx, uint16 revision, int num_aces, SEC_ACE *a 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 --git a/source3/lib/secdesc.c b/source3/lib/secdesc.c index 411185dbfa..686a4edf77 100644 --- a/source3/lib/secdesc.c +++ b/source3/lib/secdesc.c @@ -187,7 +187,7 @@ SEC_DESC *make_sec_desc(TALLOC_CTX *ctx, uint16 revision, uint16 type, *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 *make_sec_desc_buf(TALLOC_CTX *ctx, size_t len, SEC_DESC *sec_desc) { 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 @@ SEC_DESC_BUF *se_create_child_secdesc(TALLOC_CTX *ctx, SEC_DESC *parent_ctr, 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 --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c index 3e5512c734..2267fba9c8 100644 --- a/source3/lib/server_mutex.c +++ b/source3/lib/server_mutex.c @@ -33,7 +33,7 @@ static char *mutex_server_name; 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 --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c index a1f42d92ee..7e485457b0 100644 --- a/source3/lib/smbldap.c +++ b/source3/lib/smbldap.c @@ -239,7 +239,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { 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 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { 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 @@ static BOOL fetch_ldap_pw(char **dn, char** pw) 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 @@ static BOOL fetch_ldap_pw(char **dn, char** pw) #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 @@ static BOOL fetch_ldap_pw(char **dn, char** pw) } 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 @@ static BOOL fetch_ldap_pw(char **dn, char** pw) 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 @@ static void smbldap_store_state(LDAP *ld, struct smbldap_state *smbldap_state) 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 @@ static int rebindproc_with_state (LDAP * ld, char **whop, char **credp, 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; @@ -1211,7 +1210,7 @@ void smbldap_free_struct(struct smbldap_state **ldap_state) 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 --git a/source3/lib/substitute.c b/source3/lib/substitute.c index 92eff625f3..6ec3bb4a76 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -224,7 +224,7 @@ static char * realloc_expand_env_var(char *str, char *p) 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 @@ char *alloc_sub_basic(const char *smb_name, const char *str) 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 @@ char *alloc_sub_basic(const char *smb_name, const char *str) 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 *alloc_sub_specified(const char *input_string, 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 *alloc_sub_advanced(int snum, const char *user, 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 --git a/source3/lib/system.c b/source3/lib/system.c index f33d1ae7d5..7434cbe35e 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -1096,7 +1096,7 @@ static char **extract_args(const char *command) 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; /* @@ -1178,7 +1178,7 @@ int sys_popen(const char *command) 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 --git a/source3/lib/system_smbd.c b/source3/lib/system_smbd.c index fd2ed24a17..eed607ee8f 100644 --- a/source3/lib/system_smbd.c +++ b/source3/lib/system_smbd.c @@ -53,7 +53,7 @@ static int getgrouplist_internals(const char *user, gid_t gid, gid_t *groups, in 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; @@ -149,7 +149,7 @@ BOOL getgroups_user(const char *user, gid_t primary_gid, int i; 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) { return False; } @@ -158,7 +158,7 @@ BOOL getgroups_user(const char *user, gid_t primary_gid, 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); @@ -207,7 +207,7 @@ NTSTATUS pdb_default_enum_group_memberships(struct pdb_methods *methods, smb_panic("primary group missing"); } - *sids = malloc(sizeof(**sids) * *num_groups); + *sids = SMB_MALLOC_ARRAY(DOM_SID, *num_groups); if (*sids == NULL) { SAFE_FREE(gids); diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c index 093a221fd3..cafe065479 100644 --- a/source3/lib/talloc.c +++ b/source3/lib/talloc.c @@ -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 @@ static TALLOC_CTX *talloc_init_internal(void) { 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 @@ static TALLOC_CTX *talloc_init_internal(void) /** 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 @@ void *talloc(TALLOC_CTX *t, size_t size) 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 @@ void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size) /* 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 @@ void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size) 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 @@ const char * talloc_pool_name(TALLOC_CTX const *t) /** 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 @@ void *talloc_zero(TALLOC_CTX *t, size_t size) 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 @@ void *talloc_memdup(TALLOC_CTX *t, const void *p, size_t size) 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 @@ char *talloc_strdup_upper(TALLOC_CTX *t, const char *p) 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 @@ smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p) 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 @@ smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p) 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 --git a/source3/lib/time.c b/source3/lib/time.c index e63e0b2965..e7b537151f 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -190,8 +190,7 @@ static int TimeZoneFaster(time_t t) 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 --git a/source3/lib/util.c b/source3/lib/util.c index 0d5c7d7f07..ce8495e82e 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -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 @@ static char **smb_my_netbios_names; 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 @@ const char *global_myname(void) 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 @@ const char *lp_workgroup(void) 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 @@ static BOOL allocate_my_netbios_names_array(size_t number) 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 @@ static BOOL set_my_netbios_names(const char *name, int i) { 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 @@ void add_gid_to_array_unique(gid_t gid, gid_t **gids, int *num) 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 @@ const char *get_numlist(const char *p, uint32 **num, int *count) 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 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn) 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 @@ BOOL yesno(char *p) 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 @@ void *Realloc(void *p,size_t size) 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 @@ void *Realloc(void *p,size_t size) return(ret); } -void *Realloc_zero(void *ptr, size_t size) +/**************************************************************************** + Type-safe realloc. +****************************************************************************/ + +void *realloc_array(void *p,size_t el_size, unsigned int count) { - void *tptr = NULL; - - tptr = Realloc(ptr, size); - if(tptr == NULL) + 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 @@ void set_namearray(name_compare_entry **ppname_array, char *namelist) 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 @@ void set_namearray(name_compare_entry **ppname_array, char *namelist) 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 @@ int smb_mkstemp(char *template) 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_xmalloc(size_t size) 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,10 +2233,19 @@ void *smb_xmemdup(const void *p, size_t size) 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_xstrdup(const char *s) 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 *memdup(const void *p, size_t size) void *p2; if (size == 0) return NULL; - p2 = malloc(size); + p2 = SMB_MALLOC(size); if (!p2) return NULL; memcpy(p2, p, size); diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index 303d961df5..963d610bef 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -282,7 +282,7 @@ char *fgets_slash(char *s2,int maxlen,XFILE *f) if (!s2) { maxlen = MIN(maxlen,8); - s = (char *)malloc(maxlen); + s = (char *)SMB_MALLOC(maxlen); } if (!s) { @@ -325,7 +325,7 @@ char *fgets_slash(char *s2,int maxlen,XFILE *f) 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 @@ char *file_pload(char *syscmd, size_t *size) 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 @@ char *fd_load(int fd, size_t *size) 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 @@ static char **file_lines_parse(char *p, size_t size, int *numlines) 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 --git a/source3/lib/util_getent.c b/source3/lib/util_getent.c index 4431d6a2a4..1b01cae5fa 100644 --- a/source3/lib/util_getent.c +++ b/source3/lib/util_getent.c @@ -33,7 +33,7 @@ struct sys_grent * getgrent_list(void) 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 @@ struct sys_grent * getgrent_list(void) 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 @@ struct sys_grent * getgrent_list(void) ; /* 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 * getpwent_list(void) 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 @@ struct sys_pwent * getpwent_list(void) 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 @@ static struct sys_userlist *add_members_to_userlist(struct sys_userlist *list_he ; 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 --git a/source3/lib/util_pw.c b/source3/lib/util_pw.c index e102f2ef81..0d7ffe09e9 100644 --- a/source3/lib/util_pw.c +++ b/source3/lib/util_pw.c @@ -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 --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index 6b27fc84dd..197157a2f7 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -304,7 +304,7 @@ BOOL string_to_sid(DOM_SID *sidout, const char *sidstr) 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 *sid_binstring(const DOM_SID *sid) { 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 @@ DOM_SID *sid_dup_talloc(TALLOC_CTX *ctx, const DOM_SID *src) 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 --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 27a7551e37..c09e4579c4 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -818,7 +818,7 @@ BOOL open_any_socket_out(struct sockaddr_in *addrs, int num_addrs, timeout *= 1000; /* convert to microseconds */ - sockets = malloc(num_addrs * sizeof(*sockets)); + sockets = SMB_MALLOC_ARRAY(int, num_addrs); if (sockets == NULL) return False; diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index a758aece4c..c6b6570f5c 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -134,7 +134,7 @@ char **toktocliplist(int *ctok, const char *sep) *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 @@ void hex_encode(const unsigned char *buff_in, size_t len, char **out_hex_buffer) 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 @@ static BOOL string_init(char **dest,const char *src) 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 @@ static BOOL string_init(char **dest,const char *src) } *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 @@ char *realloc_string_sub(char *string, const char *pattern, const char *insert) 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 @@ char *realloc_string_sub(char *string, const char *pattern, const char *insert) 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 @@ static smb_ucs2_t *all_string_sub_w(const smb_ucs2_t *s, const smb_ucs2_t *patte } } - 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 *binary_string(char *buf, int len) 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 @@ int fstr_sprintf(fstring s, const char *fmt, ...) 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 @@ char **str_list_make(const char *string, const char *sep) 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 @@ char **str_list_make(const char *string, const char *sep) while (next_token(&str, tok, sep, sizeof(tok))) { if (num == lsize) { lsize += S_LIST_ABS; - rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1))); + rlist = 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 @@ char **str_list_make(const char *string, const char *sep) 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 @@ BOOL str_list_copy(char ***dest, const char **src) while (src[num]) { if (num == lsize) { lsize += S_LIST_ABS; - rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1))); + rlist = 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 @@ BOOL str_list_copy(char ***dest, const char **src) 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 @@ BOOL str_list_substitute(char **list, const char *pattern, const char *insert) 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 @@ int ipstr_list_parse(const char* ipstr_list, struct ip_service **ip_list) 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 @@ char * base64_encode_data_blob(DATA_BLOB data) 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 @@ void string_append(char **left, const char *right) 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 --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 997dde91c2..bb9d69b164 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -61,7 +61,7 @@ void load_case_tables(void) 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 @@ void load_case_tables(void) 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 @@ void init_valid_table(void) 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 *unistr2_tdup(TALLOC_CTX *ctx, const UNISTR2 *str) 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 *strndup_w(const smb_ucs2_t *src, size_t len) 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; @@ -815,12 +815,12 @@ UNISTR2* ucs2_to_unistr2(TALLOC_CTX *ctx, UNISTR2* dst, smb_ucs2_t* src) /* 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 --git a/source3/lib/wins_srv.c b/source3/lib/wins_srv.c index 4a54762fde..b82e04e13c 100644 --- a/source3/lib/wins_srv.c +++ b/source3/lib/wins_srv.c @@ -72,8 +72,8 @@ static char *wins_srv_keystr(struct in_addr wins_ip, struct in_addr src_ip) { 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 @@ char **wins_srv_tags(void) 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 @@ char **wins_srv_tags(void) } /* 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 --git a/source3/lib/xfile.c b/source3/lib/xfile.c index da5ec126c1..5bb93179af 100644 --- a/source3/lib/xfile.c +++ b/source3/lib/xfile.c @@ -80,7 +80,7 @@ static int x_allocate_buffer(XFILE *f) { 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 *x_fopen(const char *fname, int flags, mode_t mode) { XFILE *ret; - ret = (XFILE *)malloc(sizeof(XFILE)); + ret = SMB_MALLOC_P(XFILE); if (!ret) return NULL; memset(ret, 0, sizeof(XFILE)); |