summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/auth/auth.c4
-rw-r--r--source3/auth/auth_ntlmssp.c2
-rw-r--r--source3/auth/auth_util.c28
-rw-r--r--source3/client/client.c28
-rw-r--r--source3/client/clitar.c22
-rw-r--r--source3/groupdb/mapping.c8
-rw-r--r--source3/include/smb.h5
-rw-r--r--source3/include/smb_macros.h88
-rw-r--r--source3/intl/lang_tdb.c8
-rw-r--r--source3/lib/access.c2
-rw-r--r--source3/lib/account_pol.c2
-rw-r--r--source3/lib/adt_tree.c16
-rw-r--r--source3/lib/bitmap.c8
-rw-r--r--source3/lib/charcnv.c10
-rw-r--r--source3/lib/data_blob.c6
-rw-r--r--source3/lib/debug.c13
-rw-r--r--source3/lib/dprintf.c2
-rw-r--r--source3/lib/gencache.c23
-rw-r--r--source3/lib/iconv.c8
-rw-r--r--source3/lib/interface.c4
-rw-r--r--source3/lib/ldap_escape.c4
-rw-r--r--source3/lib/messages.c4
-rw-r--r--source3/lib/module.c4
-rw-r--r--source3/lib/ms_fnmatch.c2
-rw-r--r--source3/lib/privileges.c12
-rw-r--r--source3/lib/secace.c4
-rw-r--r--source3/lib/secacl.c4
-rw-r--r--source3/lib/secdesc.c6
-rw-r--r--source3/lib/server_mutex.c2
-rw-r--r--source3/lib/smbldap.c25
-rw-r--r--source3/lib/substitute.c10
-rw-r--r--source3/lib/system.c4
-rw-r--r--source3/lib/system_smbd.c8
-rw-r--r--source3/lib/talloc.c84
-rw-r--r--source3/lib/time.c3
-rw-r--r--source3/lib/util.c159
-rw-r--r--source3/lib/util_file.c10
-rw-r--r--source3/lib/util_getent.c30
-rw-r--r--source3/lib/util_pw.c2
-rw-r--r--source3/lib/util_sid.c6
-rw-r--r--source3/lib/util_sock.c2
-rw-r--r--source3/lib/util_str.c38
-rw-r--r--source3/lib/util_unistr.c14
-rw-r--r--source3/lib/wins_srv.c12
-rw-r--r--source3/lib/xfile.c4
-rw-r--r--source3/libads/ads_struct.c12
-rw-r--r--source3/libads/authdata.c34
-rw-r--r--source3/libads/kerberos_keytab.c2
-rw-r--r--source3/libads/kerberos_verify.c2
-rw-r--r--source3/libads/krb5_setpw.c8
-rw-r--r--source3/libads/ldap.c60
-rw-r--r--source3/libads/ldap_printer.c5
-rw-r--r--source3/libads/ldap_utils.c2
-rw-r--r--source3/libads/sasl.c2
-rw-r--r--source3/libsmb/asn1.c10
-rw-r--r--source3/libsmb/clientgen.c6
-rw-r--r--source3/libsmb/clifile.c6
-rw-r--r--source3/libsmb/clilist.c4
-rw-r--r--source3/libsmb/cliquota.c8
-rw-r--r--source3/libsmb/clireadwrite.c4
-rw-r--r--source3/libsmb/clitrans.c8
-rw-r--r--source3/libsmb/conncache.c3
-rw-r--r--source3/libsmb/libsmb_cache.c10
-rw-r--r--source3/libsmb/libsmb_compat.c2
-rw-r--r--source3/libsmb/libsmbclient.c46
-rw-r--r--source3/libsmb/namequery.c21
-rw-r--r--source3/libsmb/nmblib.c17
-rw-r--r--source3/libsmb/ntlmssp.c4
-rw-r--r--source3/libsmb/samlogon_cache.c2
-rw-r--r--source3/libsmb/smb_signing.c10
-rw-r--r--source3/libsmb/spnego.c5
-rw-r--r--source3/locking/brlock.c2
-rw-r--r--source3/locking/locking.c8
-rw-r--r--source3/locking/posix.c11
-rw-r--r--source3/modules/vfs_netatalk.c7
-rw-r--r--source3/modules/vfs_recycle.c10
-rw-r--r--source3/modules/vfs_shadow_copy.c6
-rw-r--r--source3/nmbd/nmbd_become_lmb.c4
-rw-r--r--source3/nmbd/nmbd_browserdb.c2
-rw-r--r--source3/nmbd/nmbd_browsesync.c2
-rw-r--r--source3/nmbd/nmbd_incomingrequests.c2
-rw-r--r--source3/nmbd/nmbd_namelistdb.c8
-rw-r--r--source3/nmbd/nmbd_nameregister.c4
-rw-r--r--source3/nmbd/nmbd_packets.c10
-rw-r--r--source3/nmbd/nmbd_processlogon.c3
-rw-r--r--source3/nmbd/nmbd_responserecordsdb.c4
-rw-r--r--source3/nmbd/nmbd_serverlistdb.c2
-rw-r--r--source3/nmbd/nmbd_subnetdb.c4
-rw-r--r--source3/nmbd/nmbd_synclists.c2
-rw-r--r--source3/nmbd/nmbd_winsproxy.c4
-rw-r--r--source3/nmbd/nmbd_winsserver.c6
-rw-r--r--source3/nmbd/nmbd_workgroupdb.c2
-rw-r--r--source3/nsswitch/wb_client.c2
-rw-r--r--source3/nsswitch/winbindd.c3
-rw-r--r--source3/nsswitch/winbindd_acct.c8
-rw-r--r--source3/nsswitch/winbindd_ads.c34
-rw-r--r--source3/nsswitch/winbindd_cache.c28
-rw-r--r--source3/nsswitch/winbindd_cm.c8
-rw-r--r--source3/nsswitch/winbindd_dual.c2
-rw-r--r--source3/nsswitch/winbindd_group.c28
-rw-r--r--source3/nsswitch/winbindd_misc.c6
-rw-r--r--source3/nsswitch/winbindd_pam.c8
-rw-r--r--source3/nsswitch/winbindd_passdb.c18
-rw-r--r--source3/nsswitch/winbindd_rpc.c19
-rw-r--r--source3/nsswitch/winbindd_user.c13
-rw-r--r--source3/nsswitch/winbindd_util.c4
-rw-r--r--source3/nsswitch/winbindd_wins.c2
-rw-r--r--source3/nsswitch/wins.c2
-rw-r--r--source3/param/loadparm.c39
-rw-r--r--source3/param/params.c10
-rw-r--r--source3/passdb/login_cache.c10
-rw-r--r--source3/passdb/lookup_sid.c4
-rw-r--r--source3/passdb/machine_sid.c2
-rw-r--r--source3/passdb/passdb.c6
-rw-r--r--source3/passdb/pdb_get_set.c2
-rw-r--r--source3/passdb/pdb_interface.c6
-rw-r--r--source3/passdb/pdb_ldap.c10
-rw-r--r--source3/passdb/pdb_smbpasswd.c4
-rw-r--r--source3/passdb/pdb_sql.c4
-rw-r--r--source3/passdb/pdb_tdb.c4
-rw-r--r--source3/passdb/privileges.c10
-rw-r--r--source3/passdb/secrets.c10
-rw-r--r--source3/passdb/util_sam_sid.c8
-rw-r--r--source3/printing/load.c2
-rw-r--r--source3/printing/notify.c16
-rw-r--r--source3/printing/nt_printing.c50
-rw-r--r--source3/printing/print_cups.c2
-rw-r--r--source3/printing/print_generic.c2
-rw-r--r--source3/printing/printing.c8
-rw-r--r--source3/printing/printing_db.c2
-rw-r--r--source3/registry/reg_cachehook.c2
-rw-r--r--source3/registry/reg_db.c4
-rw-r--r--source3/registry/reg_frontend.c2
-rw-r--r--source3/registry/reg_objects.c24
-rw-r--r--source3/registry/reg_printing.c14
-rw-r--r--source3/rpc_client/cli_ds.c24
-rw-r--r--source3/rpc_client/cli_echo.c38
-rw-r--r--source3/rpc_client/cli_lsarpc.c43
-rw-r--r--source3/rpc_client/cli_samr.c20
-rw-r--r--source3/rpc_client/cli_spoolss.c36
-rw-r--r--source3/rpc_client/cli_srvsvc.c12
-rw-r--r--source3/rpc_parse/parse_dfs.c8
-rw-r--r--source3/rpc_parse/parse_ds.c4
-rw-r--r--source3/rpc_parse/parse_echo.c8
-rw-r--r--source3/rpc_parse/parse_lsa.c58
-rw-r--r--source3/rpc_parse/parse_misc.c80
-rw-r--r--source3/rpc_parse/parse_net.c49
-rw-r--r--source3/rpc_parse/parse_prs.c37
-rw-r--r--source3/rpc_parse/parse_samr.c150
-rw-r--r--source3/rpc_parse/parse_sec.c12
-rw-r--r--source3/rpc_parse/parse_spoolss.c105
-rw-r--r--source3/rpc_parse/parse_srv.c34
-rw-r--r--source3/rpc_server/srv_dfs_nt.c15
-rw-r--r--source3/rpc_server/srv_echo_nt.c4
-rw-r--r--source3/rpc_server/srv_lsa_ds_nt.c2
-rw-r--r--source3/rpc_server/srv_lsa_hnd.c4
-rw-r--r--source3/rpc_server/srv_lsa_nt.c28
-rw-r--r--source3/rpc_server/srv_netlog_nt.c2
-rw-r--r--source3/rpc_server/srv_pipe.c21
-rw-r--r--source3/rpc_server/srv_pipe_hnd.c8
-rw-r--r--source3/rpc_server/srv_reg_nt.c4
-rw-r--r--source3/rpc_server/srv_samr_nt.c81
-rw-r--r--source3/rpc_server/srv_spoolss_nt.c174
-rw-r--r--source3/rpc_server/srv_srvsvc_nt.c83
-rw-r--r--source3/rpc_server/srv_util.c2
-rw-r--r--source3/rpc_server/srv_wkssvc_nt.c2
-rw-r--r--source3/rpcclient/cmd_echo.c4
-rw-r--r--source3/rpcclient/cmd_lsarpc.c2
-rw-r--r--source3/rpcclient/cmd_samr.c4
-rw-r--r--source3/rpcclient/cmd_spoolss.c7
-rw-r--r--source3/rpcclient/rpcclient.c10
-rw-r--r--source3/sam/idmap.c2
-rw-r--r--source3/sam/idmap_tdb.c2
-rw-r--r--source3/smbd/blocking.c4
-rw-r--r--source3/smbd/conn.c2
-rw-r--r--source3/smbd/dir.c6
-rw-r--r--source3/smbd/fake_file.c2
-rw-r--r--source3/smbd/fileio.c4
-rw-r--r--source3/smbd/files.c2
-rw-r--r--source3/smbd/ipc.c8
-rw-r--r--source3/smbd/lanman.c129
-rw-r--r--source3/smbd/mangle_hash.c4
-rw-r--r--source3/smbd/mangle_hash2.c18
-rw-r--r--source3/smbd/msdfs.c13
-rw-r--r--source3/smbd/notify.c2
-rw-r--r--source3/smbd/ntquotas.c6
-rw-r--r--source3/smbd/nttrans.c23
-rw-r--r--source3/smbd/open.c2
-rw-r--r--source3/smbd/oplock.c4
-rw-r--r--source3/smbd/password.c8
-rw-r--r--source3/smbd/posix_acls.c29
-rw-r--r--source3/smbd/process.c7
-rw-r--r--source3/smbd/reply.c4
-rw-r--r--source3/smbd/sec_ctx.c4
-rw-r--r--source3/smbd/session.c6
-rw-r--r--source3/smbd/statcache.c6
-rw-r--r--source3/smbd/trans2.c40
-rw-r--r--source3/smbd/vfs.c8
-rw-r--r--source3/tdb/tdb.c24
-rw-r--r--source3/tdb/tdbback.c13
-rw-r--r--source3/tdb/tdbutil.c6
-rw-r--r--source3/utils/net.c20
-rw-r--r--source3/utils/net_ads.c6
-rw-r--r--source3/utils/net_cache.c2
-rw-r--r--source3/utils/net_idmap.c2
-rw-r--r--source3/utils/net_rap.c2
-rw-r--r--source3/utils/net_rpc.c25
-rw-r--r--source3/utils/net_rpc_join.c2
-rw-r--r--source3/utils/net_rpc_printer.c8
-rw-r--r--source3/utils/net_rpc_samsync.c2
-rw-r--r--source3/utils/net_status.c3
-rw-r--r--source3/utils/ntlm_auth.c28
-rw-r--r--source3/utils/pdbedit.c4
-rw-r--r--source3/utils/smbcacls.c6
-rw-r--r--source3/utils/smbtree.c2
-rw-r--r--source3/web/cgi.c20
-rw-r--r--source3/web/neg_lang.c4
-rw-r--r--source3/web/statuspage.c4
218 files changed, 1740 insertions, 1541 deletions
diff --git a/source3/auth/auth.c b/source3/auth/auth.c
index 7cfe3fc639..b777e97cc9 100644
--- a/source3/auth/auth.c
+++ b/source3/auth/auth.c
@@ -49,7 +49,7 @@ NTSTATUS smb_register_auth(int version, const char *name, auth_init_function ini
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 @@ static NTSTATUS make_auth_context(struct auth_context **auth_context)
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 --git a/source3/auth/auth_ntlmssp.c b/source3/auth/auth_ntlmssp.c
index 4b425056b1..0e2c359251 100644
--- a/source3/auth/auth_ntlmssp.c
+++ b/source3/auth/auth_ntlmssp.c
@@ -135,7 +135,7 @@ NTSTATUS auth_ntlmssp_start(AUTH_NTLMSSP_STATE **auth_ntlmssp_state)
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 --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c
index 1ef64ab845..d985c0a54f 100644
--- a/source3/auth/auth_util.c
+++ b/source3/auth/auth_util.c
@@ -132,7 +132,7 @@ static NTSTATUS make_user_info(auth_usersupplied_info **user_info,
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 @@ static NTSTATUS make_user_info(auth_usersupplied_info **user_info,
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 @@ static NTSTATUS make_user_info(auth_usersupplied_info **user_info,
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 @@ static NTSTATUS make_user_info(auth_usersupplied_info **user_info,
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 @@ static NTSTATUS make_user_info(auth_usersupplied_info **user_info,
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 @@ static NTSTATUS make_user_info(auth_usersupplied_info **user_info,
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 @@ static NTSTATUS create_nt_user_token(const DOM_SID *user_sid, const DOM_SID *gro
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 @@ static NTSTATUS create_nt_user_token(const DOM_SID *user_sid, const DOM_SID *gro
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 @@ NT_USER_TOKEN *create_nt_token(uid_t uid, gid_t gid, int ngroups, gid_t *groups,
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;
@@ -685,7 +685,7 @@ static NTSTATUS get_user_groups(const char *username, uid_t uid, gid_t gid,
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"));
@@ -715,7 +715,7 @@ static NTSTATUS get_user_groups(const char *username, uid_t uid, gid_t gid,
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;
@@ -1244,7 +1244,7 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
/* 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"));
@@ -1393,7 +1393,7 @@ BOOL make_auth_methods(struct auth_context *auth_context, auth_methods **auth_me
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;
@@ -1428,7 +1428,7 @@ NT_USER_TOKEN *dup_nt_token(NT_USER_TOKEN *ptoken)
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 --git a/source3/client/client.c b/source3/client/client.c
index 8c43f4e16e..7470a7ba5f 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -387,7 +387,7 @@ static void init_do_list_queue(void)
{
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 @@ static void add_to_do_list_queue(const char* entry)
do_list_queue_size *= 2;
DEBUG(4,("enlarging do_list_queue to %d\n",
(int)do_list_queue_size));
- dlq = Realloc(do_list_queue, do_list_queue_size);
+ dlq = 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 @@ static int do_get(char *rname, char *lname, BOOL reget)
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 @@ static int do_put(char *rname, char *lname, BOOL reput)
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 @@ static int file_find(struct file_list **list, const char *directory,
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);
@@ -2698,7 +2698,7 @@ static void completion_remote_filter(file_info *f, const char *mask, void *state
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;
@@ -2709,7 +2709,7 @@ static void completion_remote_filter(file_info *f, const char *mask, void *state
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;
@@ -2740,7 +2740,7 @@ static char **remote_completion(const char *text, int len)
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;
@@ -2761,9 +2761,9 @@ static char **remote_completion(const char *text, int len)
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);
@@ -2818,7 +2818,7 @@ static char **completion_fn(const char *text, int start, int end)
char **matches;
int i, len, samelen = 0, count=1;
- matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
+ matches = SMB_MALLOC_ARRAY(char *, MAX_COMPLETIONS);
if (!matches) {
return NULL;
}
@@ -2827,7 +2827,7 @@ static char **completion_fn(const char *text, int start, int end)
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)
@@ -2844,10 +2844,10 @@ static char **completion_fn(const char *text, int start, int end)
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 --git a/source3/client/clitar.c b/source3/client/clitar.c
index b4d6273f7b..a92be1abe3 100644
--- a/source3/client/clitar.c
+++ b/source3/client/clitar.c
@@ -146,7 +146,7 @@ static char *string_create_s(int size)
{
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 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m
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 @@ static void initarbuf(void)
{
/* 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 @@ static char *get_longfilename(file_info2 finfo)
/* 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 @@ static int read_inclusion_file(char *filename)
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 @@ static int read_inclusion_file(char *filename)
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 @@ static int read_inclusion_file(char *filename)
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 @@ static int read_inclusion_file(char *filename)
/* 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 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind)
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 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind)
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 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind)
#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 --git a/source3/groupdb/mapping.c b/source3/groupdb/mapping.c
index 072304ed18..7095997dc8 100644
--- a/source3/groupdb/mapping.c
+++ b/source3/groupdb/mapping.c
@@ -469,7 +469,7 @@ static BOOL enum_group_mapping(enum SID_NAME_USE sid_name_use, GROUP_MAP **rmap,
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);
@@ -613,7 +613,7 @@ static NTSTATUS add_aliasmem(const DOM_SID *alias, const DOM_SID *member)
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)
@@ -753,7 +753,7 @@ static NTSTATUS del_aliasmem(const DOM_SID *alias, const DOM_SID *member)
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);
@@ -1292,7 +1292,7 @@ NTSTATUS pdb_default_enum_aliases(struct pdb_methods *methods,
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 --git a/source3/include/smb.h b/source3/include/smb.h
index bc99a2a6fd..49d3d29ac0 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -53,9 +53,6 @@ typedef int BOOL;
#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 @@ struct unix_error_map {
#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 --git a/source3/include/smb_macros.h b/source3/include/smb_macros.h
index a9e911c066..4fa9ffa5ac 100644
--- a/source3/include/smb_macros.h
+++ b/source3/include/smb_macros.h
@@ -261,4 +261,92 @@ copy an IP address from one buffer to another
#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 --git a/source3/intl/lang_tdb.c b/source3/intl/lang_tdb.c
index fe2ad5b2fc..d3422f0d78 100644
--- a/source3/intl/lang_tdb.c
+++ b/source3/intl/lang_tdb.c
@@ -148,7 +148,7 @@ BOOL lang_tdb_init(const char *lang)
strerror(errno)));
goto done;
}
- current_lang = strdup(lang);
+ current_lang = SMB_STRDUP(lang);
result = True;
goto done;
}
@@ -160,7 +160,7 @@ BOOL lang_tdb_init(const char *lang)
tdb_store_int32(tdb, "/LOADTIME/", (int)time(NULL));
}
- current_lang = strdup(lang);
+ current_lang = SMB_STRDUP(lang);
result = True;
done:
@@ -194,7 +194,7 @@ const char *lang_msg(const char *msgid)
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 @@ const char *lang_msg(const char *msgid)
/* 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 --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));
diff --git a/source3/libads/ads_struct.c b/source3/libads/ads_struct.c
index 92f37093f4..e8546f86f5 100644
--- a/source3/libads/ads_struct.c
+++ b/source3/libads/ads_struct.c
@@ -31,7 +31,7 @@ char *ads_build_path(const char *realm, const char *sep, const char *field, int
char *ret;
int len;
- r = strdup(realm);
+ r = SMB_STRDUP(realm);
if (!r || !*r)
return r;
@@ -42,7 +42,7 @@ char *ads_build_path(const char *realm, const char *sep, const char *field, int
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_init(const char *realm,
{
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 --git a/source3/libads/authdata.c b/source3/libads/authdata.c
index 29170af377..ccaf82124c 100644
--- a/source3/libads/authdata.c
+++ b/source3/libads/authdata.c
@@ -59,7 +59,7 @@ static BOOL pac_io_unknown_type_10(const char *desc, UNKNOWN_TYPE_10 *type_10,
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 @@ static BOOL pac_io_krb_sids(const char *desc, KRB_SID_AND_ATTRS *sid_and_attr,
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 @@ static BOOL pac_io_krb_sid_and_attr_array(const char *desc,
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 @@ static BOOL pac_io_group_membership_array(const char *desc,
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 @@ static BOOL pac_io_pac_signature_data(const char *desc,
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 @@ static BOOL pac_io_pac_info_hdr_ctr(const char *desc, PAC_INFO_HDR *hdr,
}
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 @@ static BOOL pac_io_pac_info_hdr_ctr(const char *desc, PAC_INFO_HDR *hdr,
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 @@ static BOOL pac_io_pac_info_hdr_ctr(const char *desc, PAC_INFO_HDR *hdr,
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 @@ static BOOL pac_io_pac_info_hdr_ctr(const char *desc, PAC_INFO_HDR *hdr,
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 @@ static BOOL pac_io_pac_info_hdr_ctr(const char *desc, PAC_INFO_HDR *hdr,
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 @@ static BOOL pac_io_pac_data(const char *desc, PAC_DATA *data,
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 @@ PAC_DATA *decode_pac_data(DATA_BLOB *auth_data, TALLOC_CTX *ctx)
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 --git a/source3/libads/kerberos_keytab.c b/source3/libads/kerberos_keytab.c
index ec6a8c5078..8475f70ec4 100644
--- a/source3/libads/kerberos_keytab.c
+++ b/source3/libads/kerberos_keytab.c
@@ -546,7 +546,7 @@ int ads_keytab_create_default(ADS_STRUCT *ads)
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 --git a/source3/libads/kerberos_verify.c b/source3/libads/kerberos_verify.c
index 848bd61acc..f7cbe8674b 100644
--- a/source3/libads/kerberos_verify.c
+++ b/source3/libads/kerberos_verify.c
@@ -174,7 +174,7 @@ static BOOL ads_secrets_verify_ticket(krb5_context context, krb5_auth_context au
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 --git a/source3/libads/krb5_setpw.c b/source3/libads/krb5_setpw.c
index 9582574851..dadce2593c 100644
--- a/source3/libads/krb5_setpw.c
+++ b/source3/libads/krb5_setpw.c
@@ -54,7 +54,7 @@ static DATA_BLOB encode_krb5_setpw(const char *principal, const char *password)
DATA_BLOB ret;
- princ = strdup(principal);
+ princ = SMB_STRDUP(principal);
if ((c = strchr_m(princ, '/')) == NULL) {
c = princ;
@@ -156,7 +156,7 @@ static krb5_error_code build_kpasswd_request(uint16 pversion,
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 @@ static ADS_STATUS do_krb5_kpasswd_request(krb5_context context,
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 @@ static ADS_STATUS ads_krb5_chg_password(const char *kdc_host,
/* 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 --git a/source3/libads/ldap.c b/source3/libads/ldap.c
index 7bddc0e9b5..c18e253f7b 100644
--- a/source3/libads/ldap.c
+++ b/source3/libads/ldap.c
@@ -119,7 +119,7 @@ static BOOL ads_try_connect(ADS_STRUCT *ads, const char *server, unsigned port)
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) {
@@ -296,11 +296,11 @@ got_connection:
}
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
@@ -338,13 +338,13 @@ static struct berval *dup_berval(TALLOC_CTX *ctx, const struct berval *in_val)
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;
}
@@ -358,9 +358,9 @@ static struct berval **ads_dup_values(TALLOC_CTX *ctx,
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++) {
@@ -378,8 +378,9 @@ static char **ads_push_strvals(TALLOC_CTX *ctx, const char **in_vals)
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++) {
@@ -397,8 +398,9 @@ static char **ads_pull_strvals(TALLOC_CTX *ctx, const char **in_vals)
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++) {
@@ -824,8 +826,7 @@ ADS_MODLIST ads_init_mods(TALLOC_CTX *ctx)
#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;
@@ -861,8 +862,8 @@ static ADS_STATUS ads_modlist_add(TALLOC_CTX *ctx, ADS_MODLIST *mods,
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 *));
@@ -870,7 +871,7 @@ static ADS_STATUS ads_modlist_add(TALLOC_CTX *ctx, ADS_MODLIST *mods,
*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) {
@@ -1046,11 +1047,11 @@ char *ads_ou_string(ADS_STRUCT *ads, const char *org_unit)
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);
@@ -1107,7 +1108,7 @@ char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid)
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);
}
@@ -1741,7 +1742,7 @@ ADS_STATUS ads_join_realm(ADS_STRUCT *ads, const char *machine_name,
char *machine;
/* machine name must be lowercase */
- machine = strdup(machine_name);
+ machine = SMB_STRDUP(machine_name);
strlower_m(machine);
/*
@@ -1791,7 +1792,7 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname)
int rc;
/* hostname must be lowercase */
- host = strdup(hostname);
+ host = SMB_STRDUP(hostname);
strlower_m(host);
status = ads_find_machine_acct(ads, &res, host);
@@ -1915,7 +1916,7 @@ ADS_STATUS ads_set_machine_sd(ADS_STRUCT *ads, const char *hostname, char *dn)
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;
@@ -2015,7 +2016,7 @@ char **ads_pull_strings(ADS_STRUCT *ads,
*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;
@@ -2126,9 +2127,8 @@ char **ads_pull_strings_range(ADS_STRUCT *ads,
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);
@@ -2265,7 +2265,7 @@ int ads_pull_sids(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx,
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;
@@ -2446,7 +2446,7 @@ ADS_STATUS ads_server_info(ADS_STRUCT *ads)
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);
@@ -2461,7 +2461,7 @@ ADS_STATUS ads_server_info(ADS_STRUCT *ads)
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 --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c
index d8e4cefcfa..68e6735891 100644
--- a/source3/libads/ldap_printer.c
+++ b/source3/libads/ldap_printer.c
@@ -161,10 +161,9 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods,
};
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 --git a/source3/libads/ldap_utils.c b/source3/libads/ldap_utils.c
index 991f16c845..03cdd339f0 100644
--- a/source3/libads/ldap_utils.c
+++ b/source3/libads/ldap_utils.c
@@ -42,7 +42,7 @@ ADS_STATUS ads_do_search_retry(ADS_STRUCT *ads, const char *bind_path, int scope
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 --git a/source3/libads/sasl.c b/source3/libads/sasl.c
index 8eb2c86bed..97ba9c9286 100644
--- a/source3/libads/sasl.c
+++ b/source3/libads/sasl.c
@@ -374,7 +374,7 @@ static ADS_STATUS ads_sasl_gssapi_bind(ADS_STRUCT *ads)
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 --git a/source3/libsmb/asn1.c b/source3/libsmb/asn1.c
index 2807b4e1d3..6db12fc612 100644
--- a/source3/libsmb/asn1.c
+++ b/source3/libsmb/asn1.c
@@ -32,7 +32,7 @@ BOOL asn1_write(ASN1_DATA *data, const void *p, int len)
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 @@ BOOL asn1_push_tag(ASN1_DATA *data, uint8 tag)
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 @@ BOOL asn1_start_tag(ASN1_DATA *data, uint8 tag)
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 @@ BOOL asn1_read_OID(ASN1_DATA *data, char **OID)
asn1_end_tag(data);
- *OID = strdup(oid_str);
+ *OID = SMB_STRDUP(oid_str);
return !data->has_error;
}
@@ -380,7 +380,7 @@ BOOL asn1_read_GeneralString(ASN1_DATA *data, char **s)
data->has_error = True;
return False;
}
- *s = malloc(len+1);
+ *s = SMB_MALLOC(len+1);
if (! *s) {
data->has_error = True;
return False;
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index 974ebf91f5..682e0d8b85 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -253,7 +253,7 @@ struct cli_state *cli_initialise(struct cli_state *cli)
}
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 @@ struct cli_state *cli_initialise(struct cli_state *cli)
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 --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 7816ed0fc6..9d20ed3adc 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -1351,7 +1351,7 @@ int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path)
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);
@@ -1402,7 +1402,7 @@ static BOOL cli_set_ea(struct cli_state *cli, uint16 setup, char *param, unsigne
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;
}
@@ -1558,7 +1558,7 @@ static BOOL cli_get_ea_list(struct cli_state *cli,
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 --git a/source3/libsmb/clilist.c b/source3/libsmb/clilist.c
index ab157d48e9..8ab5854c8f 100644
--- a/source3/libsmb/clilist.c
+++ b/source3/libsmb/clilist.c
@@ -282,7 +282,7 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute,
}
/* 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 @@ int cli_list_old(struct cli_state *cli,const char *Mask,uint16 attribute,
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 --git a/source3/libsmb/cliquota.c b/source3/libsmb/cliquota.c
index af8b4422b7..25c36c214f 100644
--- a/source3/libsmb/cliquota.c
+++ b/source3/libsmb/cliquota.c
@@ -321,12 +321,12 @@ BOOL cli_list_user_quota(struct cli_state *cli, int quota_fnum, SMB_NTQUOTA_LIST
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 @@ BOOL cli_list_user_quota(struct cli_state *cli, int quota_fnum, SMB_NTQUOTA_LIST
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 --git a/source3/libsmb/clireadwrite.c b/source3/libsmb/clireadwrite.c
index d1a23d36c8..3223098820 100644
--- a/source3/libsmb/clireadwrite.c
+++ b/source3/libsmb/clireadwrite.c
@@ -256,8 +256,8 @@ static BOOL cli_issue_write(struct cli_state *cli, int fnum, off_t offset,
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 --git a/source3/libsmb/clitrans.c b/source3/libsmb/clitrans.c
index ae44ca1a77..761741a91b 100644
--- a/source3/libsmb/clitrans.c
+++ b/source3/libsmb/clitrans.c
@@ -210,7 +210,7 @@ BOOL cli_receive_trans(struct cli_state *cli,int trans,
/* 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 @@ BOOL cli_receive_trans(struct cli_state *cli,int trans,
}
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 @@ BOOL cli_receive_nt_trans(struct cli_state *cli,
/* 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 @@ BOOL cli_receive_nt_trans(struct cli_state *cli,
}
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 --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c
index 15cc75b129..fe863db422 100644
--- a/source3/libsmb/conncache.c
+++ b/source3/libsmb/conncache.c
@@ -115,8 +115,7 @@ void add_failed_connection_entry(const char *domain, const char *server, NTSTATU
/* 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 --git a/source3/libsmb/libsmb_cache.c b/source3/libsmb/libsmb_cache.c
index caf226c5a6..ddb2753523 100644
--- a/source3/libsmb/libsmb_cache.c
+++ b/source3/libsmb/libsmb_cache.c
@@ -55,7 +55,7 @@ static int smbc_add_cached_server(SMBCCTX * context, SMBCSRV * new,
{
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 @@ static int smbc_add_cached_server(SMBCCTX * context, SMBCSRV * new,
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 --git a/source3/libsmb/libsmb_compat.c b/source3/libsmb/libsmb_compat.c
index c4be848cc1..83088a14de 100644
--- a/source3/libsmb/libsmb_compat.c
+++ b/source3/libsmb/libsmb_compat.c
@@ -73,7 +73,7 @@ static int add_fd(SMBCFILE * file)
return -1;
}
- f = malloc(sizeof(struct smbc_compat_fdlist));
+ f = SMB_MALLOC_P(struct smbc_compat_fdlist);
if (!f) {
errno = ENOMEM;
return -1;
diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c
index 3dec0c92b4..df9c4ddcad 100644
--- a/source3/libsmb/libsmbclient.c
+++ b/source3/libsmb/libsmbclient.c
@@ -99,7 +99,7 @@ decode_urlpart(char *segment, size_t sizeof_segment)
}
/* 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 @@ SMBCSRV *smbc_server(SMBCCTX *context,
* 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 @@ SMBCSRV *smbc_attr_server(SMBCCTX *context,
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 @@ static SMBCFILE *smbc_open_ctx(SMBCCTX *context, const char *fname, int flags, m
}
else {
- file = malloc(sizeof(SMBCFILE));
+ file = SMB_MALLOC_P(SMBCFILE);
if (!file) {
@@ -895,7 +895,7 @@ static SMBCFILE *smbc_open_ctx(SMBCCTX *context, const char *fname, int flags, m
/* 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 @@ static int add_dirent(SMBCFILE *dir, const char *name, const char *comment, uint
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 @@ static int add_dirent(SMBCFILE *dir, const char *name, const char *comment, uint
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 @@ static int add_dirent(SMBCFILE *dir, const char *name, const char *comment, uint
}
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 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname)
pstrcpy(workgroup, context->workgroup);
- dir = malloc(sizeof(*dir));
+ dir = SMB_MALLOC_P(SMBCFILE);
if (!dir) {
@@ -1847,7 +1847,7 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname)
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 @@ static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace, TALLOC_CTX *ctx)
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 @@ static SEC_DESC *sec_desc_parse(TALLOC_CTX *ctx,
}
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 @@ static SEC_DESC *sec_desc_parse(TALLOC_CTX *ctx,
}
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 @@ static SEC_DESC *sec_desc_parse(TALLOC_CTX *ctx,
}
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 @@ static SEC_DESC *sec_desc_parse(TALLOC_CTX *ctx,
}
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 * smbc_new_context(void)
{
SMBCCTX * context;
- context = malloc(sizeof(SMBCCTX));
+ context = SMB_MALLOC_P(SMBCCTX);
if (!context) {
errno = ENOMEM;
return NULL;
@@ -4281,7 +4281,7 @@ SMBCCTX * smbc_new_context(void)
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 @@ SMBCCTX * smbc_init_context(SMBCCTX * context)
*/
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 @@ SMBCCTX * smbc_init_context(SMBCCTX * context)
* 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 @@ SMBCCTX * smbc_init_context(SMBCCTX * context)
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 --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index fef769314a..e6868fb373 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -55,7 +55,7 @@ static struct node_status *parse_node_status(char *p, int *num_names, struct nod
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 @@ struct in_addr *name_query(int fd,const char *name,int name_type,
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 @@ static BOOL convert_ip2service( struct ip_service **return_iplist, struct in_add
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 @@ static BOOL resolve_lmhosts(const char *name, int name_type,
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 @@ static BOOL resolve_hosts(const char *name, int name_type,
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 @@ static BOOL resolve_ads(const char *name, int name_type,
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 @@ BOOL internal_resolve_name(const char *name, int name_type,
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 @@ static BOOL get_dc_list(const char *domain, struct ip_service **ip_list,
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 --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c
index 7f22ce0096..1c93f7b1e2 100644
--- a/source3/libsmb/nmblib.c
+++ b/source3/libsmb/nmblib.c
@@ -354,7 +354,7 @@ static BOOL parse_alloc_res_rec(char *inbuf,int *offset,int length,
{
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 @@ static struct packet_struct *copy_nmb_packet(struct packet_struct *packet)
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 @@ static struct packet_struct *copy_nmb_packet(struct packet_struct *packet)
/* 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 @@ static struct packet_struct *copy_dgram_packet(struct packet_struct *packet)
{
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 *parse_packet(char *buf,int length,
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 --git a/source3/libsmb/ntlmssp.c b/source3/libsmb/ntlmssp.c
index 6e41a61bf1..eb1fce5439 100644
--- a/source3/libsmb/ntlmssp.c
+++ b/source3/libsmb/ntlmssp.c
@@ -766,7 +766,7 @@ NTSTATUS ntlmssp_server_start(NTLMSSP_STATE **ntlmssp_state)
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 @@ NTSTATUS ntlmssp_client_start(NTLMSSP_STATE **ntlmssp_state)
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 --git a/source3/libsmb/samlogon_cache.c b/source3/libsmb/samlogon_cache.c
index ed2283725c..fdfc92a750 100644
--- a/source3/libsmb/samlogon_cache.c
+++ b/source3/libsmb/samlogon_cache.c
@@ -188,7 +188,7 @@ NET_USER_INFO_3* netsamlogon_cache_get( TALLOC_CTX *mem_ctx, const DOM_SID *user
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 --git a/source3/libsmb/smb_signing.c b/source3/libsmb/smb_signing.c
index b02a13c73e..df69ff3e41 100644
--- a/source3/libsmb/smb_signing.c
+++ b/source3/libsmb/smb_signing.c
@@ -54,7 +54,7 @@ static BOOL store_sequence_for_reply(struct outstanding_packet_lookup **list,
}
}
- t = smb_xmalloc(sizeof(*t));
+ t = SMB_XMALLOC_P(struct outstanding_packet_lookup);
ZERO_STRUCTP(t);
t->mid = mid;
@@ -459,7 +459,7 @@ BOOL cli_simple_set_signing(struct cli_state *cli,
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 @@ void cli_signing_trans_start(struct cli_state *cli, uint16 mid)
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 @@ void srv_signing_trans_start(uint16 mid)
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 @@ void srv_set_signing(const DATA_BLOB user_session_key, const DATA_BLOB response)
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 --git a/source3/libsmb/spnego.c b/source3/libsmb/spnego.c
index 50caf7b4c0..a0f5565d4f 100644
--- a/source3/libsmb/spnego.c
+++ b/source3/libsmb/spnego.c
@@ -42,12 +42,11 @@ static BOOL read_negTokenInit(ASN1_DATA *asn1, negTokenInit_t *token)
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 --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index 61144eb59a..d92027e267 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -407,7 +407,7 @@ NTSTATUS brl_lock(SMB_DEV_T dev, SMB_INO_T ino, int fnum,
}
/* 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 --git a/source3/locking/locking.c b/source3/locking/locking.c
index d4e8c493d5..b2f30a5684 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -679,7 +679,7 @@ BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type)
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 @@ BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type)
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 @@ BOOL add_deferred_open(uint16 mid, struct timeval *ptv, SMB_DEV_T dev, SMB_INO_T
/* 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 @@ BOOL add_deferred_open(uint16 mid, struct timeval *ptv, SMB_DEV_T dev, SMB_INO_T
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 --git a/source3/locking/posix.c b/source3/locking/posix.c
index 0e5edfa0eb..6ab2ed377e 100644
--- a/source3/locking/posix.c
+++ b/source3/locking/posix.c
@@ -102,7 +102,7 @@ static BOOL add_fd_to_close_entry(files_struct *fsp)
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 @@ static BOOL add_posix_lock_entry(files_struct *fsp, SMB_OFF_T start, SMB_OFF_T s
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 @@ BECOMES.....
| 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 @@ BOOL set_posix_lock(files_struct *fsp, SMB_BIG_UINT u_offset, SMB_BIG_UINT u_cou
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 @@ BOOL release_posix_lock(files_struct *fsp, SMB_BIG_UINT u_offset, SMB_BIG_UINT u
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 --git a/source3/modules/vfs_netatalk.c b/source3/modules/vfs_netatalk.c
index 68b8aad0ac..1b36914bbe 100644
--- a/source3/modules/vfs_netatalk.c
+++ b/source3/modules/vfs_netatalk.c
@@ -126,16 +126,15 @@ static void atalk_add_to_list(name_compare_entry **list)
}
}
- 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 --git a/source3/modules/vfs_recycle.c b/source3/modules/vfs_recycle.c
index 1cb1cb327b..5ff7931c58 100644
--- a/source3/modules/vfs_recycle.c
+++ b/source3/modules/vfs_recycle.c
@@ -215,12 +215,12 @@ static BOOL recycle_create_dir(vfs_handle_struct *handle, const char *dname)
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 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co
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 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co
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 --git a/source3/modules/vfs_shadow_copy.c b/source3/modules/vfs_shadow_copy.c
index 88135c0aed..133e8e9c64 100644
--- a/source3/modules/vfs_shadow_copy.c
+++ b/source3/modules/vfs_shadow_copy.c
@@ -82,7 +82,7 @@ static DIR *shadow_copy_opendir(vfs_handle_struct *handle, connection_struct *co
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 @@ static DIR *shadow_copy_opendir(vfs_handle_struct *handle, connection_struct *co
DEBUG(10,("shadow_copy_opendir: not hide [%s]\n",d->d_name));
- r = (SMB_STRUCT_DIRENT *)Realloc(dirp->dirs,(dirp->num+1)*sizeof(SMB_STRUCT_DIRENT));
+ r = SMB_REALLOC_ARRAY(dirp->dirs,SMB_STRUCT_DIRENT, dirp->num+1);
if (!r) {
DEBUG(0,("shadow_copy_opendir: Out of memory\n"));
break;
@@ -176,7 +176,7 @@ static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_str
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 --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c
index c536deb6f4..b928a8a7c5 100644
--- a/source3/nmbd/nmbd_become_lmb.c
+++ b/source3/nmbd/nmbd_become_lmb.c
@@ -206,7 +206,7 @@ static void release_1d_name( struct subnet_record *subrec, const char *workgroup
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 @@ in workgroup %s on subnet %s\n",
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 --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c
index c92513fae8..e8797a99d5 100644
--- a/source3/nmbd/nmbd_browserdb.c
+++ b/source3/nmbd/nmbd_browserdb.c
@@ -87,7 +87,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name,
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 --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c
index 56ffdc2670..03234bb98f 100644
--- a/source3/nmbd/nmbd_browsesync.c
+++ b/source3/nmbd/nmbd_browsesync.c
@@ -324,7 +324,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec,
/* 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 --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c
index 9214594096..7fac8c2573 100644
--- a/source3/nmbd/nmbd_incomingrequests.c
+++ b/source3/nmbd/nmbd_incomingrequests.c
@@ -516,7 +516,7 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru
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 --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c
index bb14ff7641..bdb308a2ea 100644
--- a/source3/nmbd/nmbd_namelistdb.c
+++ b/source3/nmbd/nmbd_namelistdb.c
@@ -181,14 +181,14 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec,
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 @@ void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip )
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 @@ void add_samba_names_to_subnet( struct subnet_record *subrec )
/* 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 --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c
index 4e11881f06..8f2a889254 100644
--- a/source3/nmbd/nmbd_nameregister.c
+++ b/source3/nmbd/nmbd_nameregister.c
@@ -306,7 +306,7 @@ static void multihomed_register_one(struct nmb_name *nmbname,
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 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags,
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 --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c
index a81b28ec74..8a111eb957 100644
--- a/source3/nmbd/nmbd_packets.c
+++ b/source3/nmbd/nmbd_packets.c
@@ -184,7 +184,7 @@ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmb
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 @@ static BOOL create_and_init_additional_record(struct packet_struct *packet,
{
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 @@ void queue_wins_refresh(struct nmb_name *nmbname,
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 @@ static BOOL create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_n
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 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE));
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 --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c
index ae4011eb8f..5c0fc2c521 100644
--- a/source3/nmbd/nmbd_processlogon.c
+++ b/source3/nmbd/nmbd_processlogon.c
@@ -577,8 +577,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
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 --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c
index 30c0c12950..a5903ef462 100644
--- a/source3/nmbd/nmbd_responserecordsdb.c
+++ b/source3/nmbd/nmbd_responserecordsdb.c
@@ -105,7 +105,7 @@ struct response_record *make_response_record( struct subnet_record *subrec,
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 @@ struct response_record *make_response_record( struct subnet_record *subrec,
} 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 --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c
index e6fad8319d..52d00e1585 100644
--- a/source3/nmbd/nmbd_serverlistdb.c
+++ b/source3/nmbd/nmbd_serverlistdb.c
@@ -137,7 +137,7 @@ workgroup %s. This is a bug.\n", name, work->work_group));
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 --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c
index 02a91f2760..ecfd92719b 100644
--- a/source3/nmbd/nmbd_subnetdb.c
+++ b/source3/nmbd/nmbd_subnetdb.c
@@ -147,7 +147,7 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type
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 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type
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 --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c
index 86f1f760fd..c6bcb3e574 100644
--- a/source3/nmbd/nmbd_synclists.c
+++ b/source3/nmbd/nmbd_synclists.c
@@ -143,7 +143,7 @@ done:
return;
}
- s = (struct sync_record *)malloc(sizeof(*s));
+ s = SMB_MALLOC_P(struct sync_record);
if (!s) goto done;
ZERO_STRUCTP(s);
diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c
index cce168adb2..b01ffcffc1 100644
--- a/source3/nmbd/nmbd_winsproxy.c
+++ b/source3/nmbd/nmbd_winsproxy.c
@@ -59,7 +59,7 @@ returned for name %s.\n", nmb_namestr(nmbname) ));
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 @@ proxy query returns.
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 --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c
index 0e0289d9a3..86f5b9c426 100644
--- a/source3/nmbd/nmbd_winsserver.c
+++ b/source3/nmbd/nmbd_winsserver.c
@@ -318,7 +318,7 @@ BOOL initialise_wins(void)
}
/* 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 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec,
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 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p,
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 --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c
index 8f3ae36b65..917116dd07 100644
--- a/source3/nmbd/nmbd_workgroupdb.c
+++ b/source3/nmbd/nmbd_workgroupdb.c
@@ -71,7 +71,7 @@ static struct work_record *create_workgroup(const char *name, int ttl)
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 --git a/source3/nsswitch/wb_client.c b/source3/nsswitch/wb_client.c
index a1c71becf0..3a920c1134 100644
--- a/source3/nsswitch/wb_client.c
+++ b/source3/nsswitch/wb_client.c
@@ -326,7 +326,7 @@ int winbind_initgroups(char *user, gid_t gid)
/* 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 --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c
index 455fb74f17..6f4a0a2753 100644
--- a/source3/nsswitch/winbindd.c
+++ b/source3/nsswitch/winbindd.c
@@ -357,8 +357,7 @@ static void new_connection(int listen_sock, BOOL privileged)
/* 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 --git a/source3/nsswitch/winbindd_acct.c b/source3/nsswitch/winbindd_acct.c
index e6496695cb..2c8b7cae28 100644
--- a/source3/nsswitch/winbindd_acct.c
+++ b/source3/nsswitch/winbindd_acct.c
@@ -219,7 +219,7 @@ static WINBINDD_GR* string2group( char *string )
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 @@ static char* group2string( const WINBINDD_GR *grp )
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 @@ static char* group2string( const WINBINDD_GR *grp )
}
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 @@ static BOOL wb_addgrpmember( WINBINDD_GR *grp, const char *user )
}
/* 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 --git a/source3/nsswitch/winbindd_ads.c b/source3/nsswitch/winbindd_ads.c
index 1392c96fb1..f77b76cd9a 100644
--- a/source3/nsswitch/winbindd_ads.c
+++ b/source3/nsswitch/winbindd_ads.c
@@ -72,7 +72,7 @@ static ADS_STRUCT *ads_cached_connection(struct winbindd_domain *domain)
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 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain,
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 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain,
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 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
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 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
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 @@ static NTSTATUS lookup_usergroups_alt(struct winbindd_domain *domain,
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 @@ static NTSTATUS lookup_usergroups_alt(struct winbindd_domain *domain,
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 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
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 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
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 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
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 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
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 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
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 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain,
/* 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 --git a/source3/nsswitch/winbindd_cache.c b/source3/nsswitch/winbindd_cache.c
index a6ebafca96..ba274ec8e7 100644
--- a/source3/nsswitch/winbindd_cache.c
+++ b/source3/nsswitch/winbindd_cache.c
@@ -136,7 +136,7 @@ static struct winbind_cache *get_cache(struct winbindd_domain *domain)
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 @@ static char *centry_string(struct cache_entry *centry, TALLOC_CTX *mem_ctx)
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 @@ static DOM_SID *centry_sid(struct cache_entry *centry, TALLOC_CTX *mem_ctx)
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 @@ static struct cache_entry *wcache_fetch(struct winbind_cache *cache,
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 @@ static void centry_expand(struct cache_entry *centry, uint32 len)
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 @@ struct cache_entry *centry_start(struct winbindd_domain *domain, NTSTATUS status
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 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain,
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 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
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 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
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 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
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 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
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 --git a/source3/nsswitch/winbindd_cm.c b/source3/nsswitch/winbindd_cm.c
index c9aef2905f..1843ec188b 100644
--- a/source3/nsswitch/winbindd_cm.c
+++ b/source3/nsswitch/winbindd_cm.c
@@ -432,7 +432,7 @@ static BOOL add_one_dc_unique(TALLOC_CTX *mem_ctx, const char *domain_name,
if (!NT_STATUS_IS_OK(check_negative_conn_cache(domain_name, dcname)))
return False;
- *dcs = talloc_realloc(mem_ctx, *dcs, ((*num)+1) * sizeof(**dcs));
+ *dcs = TALLOC_REALLOC_ARRAY(mem_ctx, *dcs, struct dc_name_ip, (*num)+1);
if (*dcs == NULL)
return False;
@@ -448,7 +448,7 @@ static BOOL add_string_to_array(TALLOC_CTX *mem_ctx,
{
char *dup_str = talloc_strdup(mem_ctx, str);
- *array = talloc_realloc(mem_ctx, *array, ((*num)+1) * sizeof(**array));
+ *array = TALLOC_REALLOC_ARRAY(mem_ctx, *array, char *, (*num)+1);
if ((*array == NULL) || (dup_str == NULL))
return False;
@@ -462,7 +462,7 @@ static BOOL add_sockaddr_to_array(TALLOC_CTX *mem_ctx,
struct in_addr ip, uint16 port,
struct sockaddr_in **addrs, int *num)
{
- *addrs = talloc_realloc(mem_ctx, *addrs, ((*num)+1) * sizeof(**addrs));
+ *addrs = TALLOC_REALLOC_ARRAY(mem_ctx, *addrs, struct sockaddr_in, (*num)+1);
if (*addrs == NULL)
return False;
@@ -753,7 +753,7 @@ static NTSTATUS new_cm_connection(struct winbindd_domain *domain, const char *pi
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 --git a/source3/nsswitch/winbindd_dual.c b/source3/nsswitch/winbindd_dual.c
index d4ec6e586d..587507ee29 100644
--- a/source3/nsswitch/winbindd_dual.c
+++ b/source3/nsswitch/winbindd_dual.c
@@ -117,7 +117,7 @@ void dual_send_request(struct winbindd_cli_state *state)
if (!background_process) return;
- list = malloc(sizeof(*list));
+ list = SMB_MALLOC_P(struct dual_list);
if (!list) return;
list->next = NULL;
diff --git a/source3/nsswitch/winbindd_group.c b/source3/nsswitch/winbindd_group.c
index 7eb0585c37..4b49c1873e 100644
--- a/source3/nsswitch/winbindd_group.c
+++ b/source3/nsswitch/winbindd_group.c
@@ -47,7 +47,7 @@ static int gr_mem_buffer( char **buffer, char **members, int num_members )
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 @@ static BOOL fill_grent_mem(struct winbindd_domain *domain,
/* 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 @@ enum winbindd_result winbindd_setgrent(struct winbindd_cli_state *state)
}
- 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 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
/* 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 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
/* 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 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
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 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
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 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
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 @@ enum winbindd_result winbindd_list_groups(struct winbindd_cli_state *state)
/* 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"));
@@ -1151,12 +1147,12 @@ static void add_sid_to_parray_unique(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
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;
@@ -1259,7 +1255,7 @@ enum winbindd_result winbindd_getusersids(struct winbindd_cli_state *state)
}
/* 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 --git a/source3/nsswitch/winbindd_misc.c b/source3/nsswitch/winbindd_misc.c
index 18478992f3..bb30a7029e 100644
--- a/source3/nsswitch/winbindd_misc.c
+++ b/source3/nsswitch/winbindd_misc.c
@@ -128,7 +128,7 @@ enum winbindd_result winbindd_list_trusted_domains(struct winbindd_cli_state
/* 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 @@ enum winbindd_result winbindd_show_sequence(struct winbindd_cli_state *state)
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 @@ enum winbindd_result winbindd_priv_pipe_dir(struct winbindd_cli_state *state)
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 --git a/source3/nsswitch/winbindd_pam.c b/source3/nsswitch/winbindd_pam.c
index e13649afe1..f7d3ac5aa4 100644
--- a/source3/nsswitch/winbindd_pam.c
+++ b/source3/nsswitch/winbindd_pam.c
@@ -43,7 +43,7 @@ static NTSTATUS append_info3_as_ndr(TALLOC_CTX *mem_ctx,
}
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 @@ static NTSTATUS check_info3_in_group(TALLOC_CTX *mem_ctx,
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 @@ done:
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 @@ enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
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 --git a/source3/nsswitch/winbindd_passdb.c b/source3/nsswitch/winbindd_passdb.c
index 3adb81caa3..a208186b5f 100644
--- a/source3/nsswitch/winbindd_passdb.c
+++ b/source3/nsswitch/winbindd_passdb.c
@@ -217,8 +217,7 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
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 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain,
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 --git a/source3/nsswitch/winbindd_rpc.c b/source3/nsswitch/winbindd_rpc.c
index ba24749fbe..de7f2ff76f 100644
--- a/source3/nsswitch/winbindd_rpc.c
+++ b/source3/nsswitch/winbindd_rpc.c
@@ -98,8 +98,7 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain,
*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 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
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 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
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 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
*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 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
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 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
#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 --git a/source3/nsswitch/winbindd_user.c b/source3/nsswitch/winbindd_user.c
index 249b9ccd8e..fc3fe0f963 100644
--- a/source3/nsswitch/winbindd_user.c
+++ b/source3/nsswitch/winbindd_user.c
@@ -351,8 +351,7 @@ enum winbindd_result winbindd_setpwent(struct winbindd_cli_state *state)
/* 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 @@ static BOOL get_sam_user_entries(struct getent_state *ent)
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 @@ enum winbindd_result winbindd_getpwent(struct winbindd_cli_state *state)
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 @@ enum winbindd_result winbindd_list_users(struct winbindd_cli_state *state)
/* 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 --git a/source3/nsswitch/winbindd_util.c b/source3/nsswitch/winbindd_util.c
index a96f652c61..7cbcba1245 100644
--- a/source3/nsswitch/winbindd_util.c
+++ b/source3/nsswitch/winbindd_util.c
@@ -139,7 +139,7 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const
/* 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 @@ DOM_SID *rid_to_talloced_sid(struct winbindd_domain *domain,
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 --git a/source3/nsswitch/winbindd_wins.c b/source3/nsswitch/winbindd_wins.c
index 107c9d264c..f199ebcb43 100644
--- a/source3/nsswitch/winbindd_wins.c
+++ b/source3/nsswitch/winbindd_wins.c
@@ -97,7 +97,7 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count)
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 --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c
index a1c4f4deec..8d26fc5297 100644
--- a/source3/nsswitch/wins.c
+++ b/source3/nsswitch/wins.c
@@ -101,7 +101,7 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count)
/* 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 --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 95f09c70e4..d0bad3ff17 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -2262,9 +2262,7 @@ static int add_a_service(const service *pservice, const char *name)
if (i == iNumServices) {
service **tsp;
- tsp = (service **) Realloc(ServicePtrs,
- sizeof(service *) *
- num_to_alloc);
+ tsp = SMB_REALLOC_ARRAY(ServicePtrs, service *, num_to_alloc);
if (!tsp) {
DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
@@ -2272,8 +2270,7 @@ static int add_a_service(const service *pservice, const char *name)
}
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"));
@@ -2565,16 +2562,16 @@ static void copy_service(service * pserviceDest, service * pserviceSource, BOOL
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);
}
@@ -2649,16 +2646,16 @@ static void add_to_file_list(const char *fname, const char *subfname)
}
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;
@@ -2708,7 +2705,7 @@ BOOL lp_file_list_changed(void)
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;
@@ -3050,7 +3047,7 @@ static void init_copymap(service * pservice)
{
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",
@@ -3104,16 +3101,16 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
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);
@@ -3656,7 +3653,7 @@ static void lp_add_auto_services(char *str)
if (!str)
return;
- s = strdup(str);
+ s = SMB_STRDUP(str);
if (!s)
return;
@@ -3755,7 +3752,7 @@ static void lp_save_defaults(void)
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;
}
@@ -3763,7 +3760,7 @@ static void lp_save_defaults(void)
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 --git a/source3/param/params.c b/source3/param/params.c
index 892e5476cc..2d6fe56716 100644
--- a/source3/param/params.c
+++ b/source3/param/params.c
@@ -238,7 +238,7 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) )
{
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 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *)
{
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 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *)
{
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 @@ static myFILE *OpenConfFile( const char *FileName )
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 @@ BOOL pm_process( const char *FileName,
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 --git a/source3/passdb/login_cache.c b/source3/passdb/login_cache.c
index 0d782912b1..d82cfcc560 100644
--- a/source3/passdb/login_cache.c
+++ b/source3/passdb/login_cache.c
@@ -72,7 +72,7 @@ LOGIN_CACHE * login_cache_read(SAM_ACCOUNT *sampass)
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 @@ LOGIN_CACHE * login_cache_read(SAM_ACCOUNT *sampass)
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 @@ BOOL login_cache_write(const SAM_ACCOUNT *sampass, LOGIN_CACHE entry)
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 @@ BOOL login_cache_write(const SAM_ACCOUNT *sampass, LOGIN_CACHE entry)
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 @@ BOOL login_cache_delentry(const SAM_ACCOUNT *sampass)
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 --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c
index 4df497461a..8a3d35defd 100644
--- a/source3/passdb/lookup_sid.c
+++ b/source3/passdb/lookup_sid.c
@@ -208,7 +208,7 @@ static void store_uid_sid_cache(const DOM_SID *psid, uid_t uid)
}
}
- 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;
@@ -282,7 +282,7 @@ static void store_gid_sid_cache(const DOM_SID *psid, gid_t gid)
}
}
- 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 --git a/source3/passdb/machine_sid.c b/source3/passdb/machine_sid.c
index ce1354ce81..ae0b16273f 100644
--- a/source3/passdb/machine_sid.c
+++ b/source3/passdb/machine_sid.c
@@ -83,7 +83,7 @@ static DOM_SID *pdb_generate_sam_sid(void)
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 --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c
index 35317b9816..aeea4316f3 100644
--- a/source3/passdb/passdb.c
+++ b/source3/passdb/passdb.c
@@ -133,7 +133,7 @@ NTSTATUS pdb_init_sam_talloc(TALLOC_CTX *mem_ctx, SAM_ACCOUNT **user)
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"));
@@ -1893,7 +1893,7 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen)
/* 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;
@@ -2172,7 +2172,7 @@ uint32 init_buffer_from_sam_v2 (uint8 **buf, const SAM_ACCOUNT *sampass, BOOL si
}
/* 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 --git a/source3/passdb/pdb_get_set.c b/source3/passdb/pdb_get_set.c
index 51c408e6d5..2ca7638472 100644
--- a/source3/passdb/pdb_get_set.c
+++ b/source3/passdb/pdb_get_set.c
@@ -1224,7 +1224,7 @@ BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext)
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 --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c
index f18ef616f0..9bc38fb444 100644
--- a/source3/passdb/pdb_interface.c
+++ b/source3/passdb/pdb_interface.c
@@ -98,7 +98,7 @@ NTSTATUS smb_register_passdb(int version, const char *name, pdb_init_function in
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;
@@ -711,7 +711,7 @@ static NTSTATUS make_pdb_context(struct pdb_context **context)
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;
@@ -1260,7 +1260,7 @@ static void pdb_default_endsampwent(struct pdb_methods *methods)
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 --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c
index 3ea291b611..a84b2f35b2 100644
--- a/source3/passdb/pdb_ldap.c
+++ b/source3/passdb/pdb_ldap.c
@@ -730,7 +730,7 @@ static BOOL init_sam_from_ldap (struct ldapsam_privates *ldap_state,
/* 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 @@ static void append_attr(char ***attr_list, const char *new_attr)
;
}
- (*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;
}
@@ -2644,7 +2644,7 @@ static NTSTATUS ldapsam_enum_group_mapping(struct pdb_methods *methods,
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);
@@ -2971,7 +2971,7 @@ static NTSTATUS pdb_init_ldapsam_common(PDB_CONTEXT *pdb_context, PDB_METHODS **
/* 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 --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c
index 805201615c..d75d0ed5c8 100644
--- a/source3/passdb/pdb_smbpasswd.c
+++ b/source3/passdb/pdb_smbpasswd.c
@@ -551,7 +551,7 @@ static char *format_new_smbpasswd_entry(const struct smb_passwd *newpwd)
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 @@ static NTSTATUS pdb_init_smbpasswd(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_m
/* 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 --git a/source3/passdb/pdb_sql.c b/source3/passdb/pdb_sql.c
index 37e408a387..820280bcbf 100644
--- a/source3/passdb/pdb_sql.c
+++ b/source3/passdb/pdb_sql.c
@@ -78,7 +78,7 @@ static void pdb_sql_int_field(struct pdb_sql_query *q, const char *name, int val
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++) {
@@ -475,7 +475,7 @@ char *sql_account_query_update(const char *location, const SAM_ACCOUNT *newpwd,
" VALUES (%s", query.part2);
}
- ret = strdup(query.part1);
+ ret = SMB_STRDUP(query.part1);
talloc_destroy(query.mem_ctx);
return ret;
}
diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c
index 5fb5ce3891..c792d229b9 100644
--- a/source3/passdb/pdb_tdb.c
+++ b/source3/passdb/pdb_tdb.c
@@ -267,7 +267,7 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data,
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 @@ static NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_meth
(*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 --git a/source3/passdb/privileges.c b/source3/passdb/privileges.c
index 624817e32e..69fc75a618 100644
--- a/source3/passdb/privileges.c
+++ b/source3/passdb/privileges.c
@@ -121,7 +121,7 @@ NTSTATUS privilege_enum_account_with_right(const char *right,
*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 @@ static NTSTATUS privilege_set_accounts_with_right(const char *right,
}
/* 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 @@ NTSTATUS privilege_add_account_right(const char *right,
}
/* 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 @@ NTSTATUS privilege_enum_account_rights(DOM_SID *sid,
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 --git a/source3/passdb/secrets.c b/source3/passdb/secrets.c
index 426217b82c..6be63e4f9d 100644
--- a/source3/passdb/secrets.c
+++ b/source3/passdb/secrets.c
@@ -346,7 +346,7 @@ BOOL secrets_fetch_trusted_domain_password(const char *domain, char** pwd,
/* the trust's password */
if (pwd) {
- *pwd = strdup(pass.pass);
+ *pwd = SMB_STRDUP(pass.pass);
if (!*pwd) {
return False;
}
@@ -577,7 +577,7 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in
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 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in
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 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in
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 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in
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 --git a/source3/passdb/util_sam_sid.c b/source3/passdb/util_sam_sid.c
index 7bc6da94c0..c93c3400bd 100644
--- a/source3/passdb/util_sam_sid.c
+++ b/source3/passdb/util_sam_sid.c
@@ -106,16 +106,16 @@ static void init_sid_name_map (void)
/* 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 @@ BOOL map_name_to_wellknown_sid(DOM_SID *sid, enum SID_NAME_USE *use, const char
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 --git a/source3/printing/load.c b/source3/printing/load.c
index cd90cbb6f3..59306aa104 100644
--- a/source3/printing/load.c
+++ b/source3/printing/load.c
@@ -40,7 +40,7 @@ static void add_auto_printers(void)
{
const char *p;
int printers;
- char *str = strdup(lp_auto_services());
+ char *str = SMB_STRDUP(lp_auto_services());
if (!str) return;
diff --git a/source3/printing/notify.c b/source3/printing/notify.c
index 77326bee3e..0071d3d8c0 100644
--- a/source3/printing/notify.c
+++ b/source3/printing/notify.c
@@ -99,7 +99,7 @@ again:
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 @@ static void print_notify_send_messages_to_printer(const char *printer, unsigned
}
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 @@ static BOOL copy_notify2_msg( SPOOLSS_NOTIFY_MSG *to, SPOOLSS_NOTIFY_MSG *from )
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 @@ static void send_spoolss_notify2_msg(SPOOLSS_NOTIFY_MSG *msg)
/* 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 @@ static void send_spoolss_notify2_msg(SPOOLSS_NOTIFY_MSG *msg)
/* 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 @@ static void send_notify_field_values(const char *sharename, uint32 type,
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 @@ static void send_notify_field_buffer(const char *sharename, uint32 type,
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 @@ BOOL print_notify_pid_list(const char *printername, TALLOC_CTX *mem_ctx, size_t
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 --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index 2dc565c79c..b17ddb51ca 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -531,7 +531,7 @@ int get_ntforms(nt_forms_struct **list)
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 @@ BOOL add_a_form(nt_forms_struct **list, const FORM *form, int *count)
}
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 @@ int get_ntdrivers(fstring **list, const char *architecture, uint32 version)
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 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
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 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
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 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
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 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
/* 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 @@ static uint32 add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
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 @@ static WERROR get_a_printer_driver_3_default(NT_PRINTER_DRIVER_INFO_LEVEL_3 **in
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 @@ static WERROR get_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 **info_ptr,
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 @@ static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info)
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 @@ NT_DEVICEMODE *construct_nt_devicemode(const fstring default_devicename)
{
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 @@ static int add_new_printer_key( NT_PRINTER_DATA *data, const char *name )
/* 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 @@ static int add_new_printer_key( NT_PRINTER_DATA *data, const char *name )
/* 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 @@ uint32 get_printer_subkeys( NT_PRINTER_DATA *data, const char* key, fstring **su
/* 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 @@ static void map_single_multi_sz_into_ctr(REGVAL_CTR *ctr, const char *val_name,
/* 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);
@@ -3773,7 +3777,7 @@ static uint32 update_driver_init_2(NT_PRINTER_INFO_LEVEL_2 *info)
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;
@@ -3897,7 +3901,7 @@ static WERROR save_driver_init_2(NT_PRINTER_INFO_LEVEL *printer, uint8 *data, ui
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;
}
@@ -4014,7 +4018,7 @@ NT_PRINTER_INFO_LEVEL_2* dup_printer_2( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL_2
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) );
@@ -4062,7 +4066,7 @@ WERROR get_a_printer( Printer_entry *print_hnd, NT_PRINTER_INFO_LEVEL **pp_print
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;
}
@@ -4123,7 +4127,7 @@ WERROR get_a_printer( Printer_entry *print_hnd, NT_PRINTER_INFO_LEVEL **pp_print
/* 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 --git a/source3/printing/print_cups.c b/source3/printing/print_cups.c
index 2a59e2c5d3..5cc36d6e17 100644
--- a/source3/printing/print_cups.c
+++ b/source3/printing/print_cups.c
@@ -909,7 +909,7 @@ cups_queue_get(const char *printer_name,
{
qalloc += 16;
- temp = Realloc(queue, sizeof(print_queue_struct) * qalloc);
+ temp = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
if (temp == NULL)
{
diff --git a/source3/printing/print_generic.c b/source3/printing/print_generic.c
index d6074704b3..256654179e 100644
--- a/source3/printing/print_generic.c
+++ b/source3/printing/print_generic.c
@@ -194,7 +194,7 @@ static int generic_queue_get(const char *printer_name,
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 --git a/source3/printing/printing.c b/source3/printing/printing.c
index 9d9ebba950..5c8790e34b 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -536,7 +536,7 @@ static BOOL pjob_store(const char* sharename, uint32 jobid, struct printjob *pjo
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;
@@ -934,7 +934,7 @@ static void store_queue_struct(struct tdb_print_db *pdb, struct traverse_struct
queue[i].fs_file);
}
- if ((data.dptr = malloc(data.dsize)) == NULL)
+ if ((data.dptr = SMB_MALLOC(data.dsize)) == NULL)
return;
len = 0;
@@ -1423,7 +1423,7 @@ BOOL print_notify_register_pid(int snum)
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));
@@ -2379,7 +2379,7 @@ static BOOL get_stored_queue_info(struct tdb_print_db *pdb, int snum, int *pcoun
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 --git a/source3/printing/printing_db.c b/source3/printing/printing_db.c
index d45ad1cff7..b9b4b3c6b0 100644
--- a/source3/printing/printing_db.c
+++ b/source3/printing/printing_db.c
@@ -80,7 +80,7 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
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 --git a/source3/registry/reg_cachehook.c b/source3/registry/reg_cachehook.c
index 547eed392d..3b75cae1a5 100644
--- a/source3/registry/reg_cachehook.c
+++ b/source3/registry/reg_cachehook.c
@@ -78,7 +78,7 @@ REGISTRY_HOOK* reghook_cache_find( char *keyname )
/* 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 --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c
index cd5ec18f02..5ac8329309 100644
--- a/source3/registry/reg_db.c
+++ b/source3/registry/reg_db.c
@@ -183,7 +183,7 @@ BOOL regdb_store_reg_keys( char *keyname, REGSUBKEY_CTR *ctr )
/* allocate some initial memory */
- buffer = malloc(sizeof(pstring));
+ buffer = SMB_MALLOC(sizeof(pstring));
buflen = sizeof(pstring);
len = 0;
@@ -197,7 +197,7 @@ BOOL regdb_store_reg_keys( char *keyname, REGSUBKEY_CTR *ctr )
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 --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c
index a9dfb52f01..1f8c936290 100644
--- a/source3/registry/reg_frontend.c
+++ b/source3/registry/reg_frontend.c
@@ -154,7 +154,7 @@ BOOL fetch_reg_keys_specific( REGISTRY_KEY *key, char** subkey, uint32 key_index
if ( !(s = regsubkey_ctr_specific_key( &ctr, key_index )) )
return False;
- *subkey = strdup( s );
+ *subkey = SMB_STRDUP( s );
return True;
}
diff --git a/source3/registry/reg_objects.c b/source3/registry/reg_objects.c
index 9cfeb7faa9..16fb7dd18d 100644
--- a/source3/registry/reg_objects.c
+++ b/source3/registry/reg_objects.c
@@ -52,16 +52,16 @@ int regsubkey_ctr_addkey( REGSUBKEY_CTR *ctr, const char *keyname )
/* 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 @@ REGISTRY_VALUE* dup_registry_value( REGISTRY_VALUE *val )
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 @@ int regval_ctr_addvalue( REGVAL_CTR *ctr, const char *name, uint16 type,
/* 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 @@ int regval_ctr_copyvalue( REGVAL_CTR *ctr, REGISTRY_VALUE *val )
/* 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 --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c
index 14eb57c6f2..ee4d1dcb64 100644
--- a/source3/registry/reg_printing.c
+++ b/source3/registry/reg_printing.c
@@ -73,7 +73,7 @@ static char* trim_reg_path( char *path )
p++;
if ( *p )
- return strdup(p);
+ return SMB_STRDUP(p);
else
return NULL;
}
@@ -136,7 +136,7 @@ static int print_subpath_environments( char *key, REGSUBKEY_CTR *subkeys )
/* 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 @@ static int print_subpath_values_environments( char *key, REGVAL_CTR *val )
/* 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 @@ static int print_subpath_values_environments( char *key, REGVAL_CTR *val )
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 @@ static int print_subpath_values_environments( char *key, REGVAL_CTR *val )
/* 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 @@ static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys )
/* 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 @@ static int print_subpath_values_printers( char *key, REGVAL_CTR *val )
goto done;
}
- key2 = strdup( key );
+ key2 = SMB_STRDUP( key );
keystr = key2;
reg_split_path( keystr, &base, &new_path );
diff --git a/source3/rpc_client/cli_ds.c b/source3/rpc_client/cli_ds.c
index 09e63a4714..1a2174d58c 100644
--- a/source3/rpc_client/cli_ds.c
+++ b/source3/rpc_client/cli_ds.c
@@ -39,8 +39,13 @@ NTSTATUS cli_ds_getprimarydominfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 @@ NTSTATUS cli_ds_getprimarydominfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ NTSTATUS cli_ds_enum_domain_trusts(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 @@ NTSTATUS cli_ds_enum_domain_trusts(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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;
@@ -153,5 +163,3 @@ done:
return result;
}
-
-
diff --git a/source3/rpc_client/cli_echo.c b/source3/rpc_client/cli_echo.c
index 03a4ab36ee..1ae7aaa8e7 100644
--- a/source3/rpc_client/cli_echo.c
+++ b/source3/rpc_client/cli_echo.c
@@ -35,8 +35,13 @@ NTSTATUS cli_echo_add_one(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 @@ NTSTATUS cli_echo_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 @@ NTSTATUS cli_echo_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ NTSTATUS cli_echo_sink_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 @@ NTSTATUS cli_echo_source_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 --git a/source3/rpc_client/cli_lsarpc.c b/source3/rpc_client/cli_lsarpc.c
index 40b83c5c0c..a8dfa93bd8 100644
--- a/source3/rpc_client/cli_lsarpc.c
+++ b/source3/rpc_client/cli_lsarpc.c
@@ -88,7 +88,7 @@ NTSTATUS cli_lsa_open_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ NTSTATUS cli_lsa_query_info_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx,
}
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 @@ NTSTATUS cli_lsa_query_info_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx,
}
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 @@ NTSTATUS cli_lsa_query_info_policy2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
}
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 @@ NTSTATUS cli_lsa_enum_trust_dom(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 @@ NTSTATUS cli_lsa_enum_trust_dom(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ NTSTATUS cli_lsa_enum_privilege(struct cli_state *cli, TALLOC_CTX *mem_ctx,
*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 @@ NTSTATUS cli_lsa_enum_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 @@ NTSTATUS cli_lsa_enum_privsaccount(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ NTSTATUS cli_lsa_enum_account_rights(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 --git a/source3/rpc_client/cli_samr.c b/source3/rpc_client/cli_samr.c
index 86f6505689..26c29474ea 100644
--- a/source3/rpc_client/cli_samr.c
+++ b/source3/rpc_client/cli_samr.c
@@ -853,13 +853,13 @@ NTSTATUS cli_samr_enum_dom_users(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ NTSTATUS cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ NTSTATUS cli_samr_enum_als_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ NTSTATUS cli_samr_query_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ NTSTATUS cli_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
}
*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 @@ NTSTATUS cli_samr_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
}
*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 --git a/source3/rpc_client/cli_spoolss.c b/source3/rpc_client/cli_spoolss.c
index dc693eb02c..5030a97c00 100644
--- a/source3/rpc_client/cli_spoolss.c
+++ b/source3/rpc_client/cli_spoolss.c
@@ -55,7 +55,7 @@ static void decode_printer_info_0(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
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 @@ static void decode_printer_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
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 @@ static void decode_printer_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
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 @@ static void decode_printer_info_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
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 @@ static void decode_printer_info_7(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
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 @@ static void decode_port_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
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 @@ static void decode_port_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
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 @@ static void decode_printer_driver_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
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 @@ static void decode_printer_driver_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
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 @@ static void decode_printer_driver_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
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 @@ static void decode_printerdriverdir_1 (TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
{
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 @@ static void decode_forms_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
{
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 @@ static void decode_jobs_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
{
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 @@ static void decode_jobs_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
{
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 @@ WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 @@ WERROR cli_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 @@ WERROR cli_spoolss_enumprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ WERROR cli_spoolss_enumprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 --git a/source3/rpc_client/cli_srvsvc.c b/source3/rpc_client/cli_srvsvc.c
index da4721c2c7..3385fbe463 100644
--- a/source3/rpc_client/cli_srvsvc.c
+++ b/source3/rpc_client/cli_srvsvc.c
@@ -120,8 +120,7 @@ WERROR cli_srvsvc_net_share_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ WERROR cli_srvsvc_net_share_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ WERROR cli_srvsvc_net_share_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ WERROR cli_srvsvc_net_file_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 --git a/source3/rpc_parse/parse_dfs.c b/source3/rpc_parse/parse_dfs.c
index 0d0ce557b2..3f7b2a4cd5 100644
--- a/source3/rpc_parse/parse_dfs.c
+++ b/source3/rpc_parse/parse_dfs.c
@@ -374,7 +374,7 @@ BOOL dfs_io_dfs_info_ctr(const char *desc, DFS_INFO_CTR* ctr, uint32 num_entries
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 @@ BOOL dfs_io_dfs_info_ctr(const char *desc, DFS_INFO_CTR* ctr, uint32 num_entries
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 @@ BOOL dfs_io_dfs_info_ctr(const char *desc, DFS_INFO_CTR* ctr, uint32 num_entries
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 @@ BOOL dfs_io_dfs_storage_info(const char *desc, DFS_INFO_3* info3, prs_struct *ps
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 --git a/source3/rpc_parse/parse_ds.c b/source3/rpc_parse/parse_ds.c
index 070f6be43a..9155419ae4 100644
--- a/source3/rpc_parse/parse_ds.c
+++ b/source3/rpc_parse/parse_ds.c
@@ -29,7 +29,7 @@ static BOOL ds_io_dominfobasic( const char *desc, prs_struct *ps, int depth, DSR
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 @@ static BOOL ds_io_dom_trusts_ctr( const char *desc, prs_struct *ps, int depth, D
/* 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 --git a/source3/rpc_parse/parse_echo.c b/source3/rpc_parse/parse_echo.c
index 4b1ff1f4d5..b4aa8de24a 100644
--- a/source3/rpc_parse/parse_echo.c
+++ b/source3/rpc_parse/parse_echo.c
@@ -67,7 +67,7 @@ BOOL echo_io_q_echo_data(const char *desc, ECHO_Q_ECHO_DATA *q_d,
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 @@ BOOL echo_io_r_echo_data(const char *desc, ECHO_R_ECHO_DATA *q_d,
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 @@ BOOL echo_io_q_sink_data(const char *desc, ECHO_Q_SINK_DATA *q_d,
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 @@ BOOL echo_io_r_source_data(const char *desc, ECHO_R_SOURCE_DATA *q_d,
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 --git a/source3/rpc_parse/parse_lsa.c b/source3/rpc_parse/parse_lsa.c
index 5fff1fea37..e2cb94c8fe 100644
--- a/source3/rpc_parse/parse_lsa.c
+++ b/source3/rpc_parse/parse_lsa.c
@@ -251,7 +251,7 @@ static BOOL lsa_io_obj_attr(const char *desc, LSA_OBJ_ATTR *attr, prs_struct *ps
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 @@ void init_r_enum_trust_dom(TALLOC_CTX *ctx, LSA_R_ENUM_TRUST_DOM *r_e, uint32 en
* 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 @@ BOOL lsa_io_r_enum_trust_dom(const char *desc, LSA_R_ENUM_TRUST_DOM *r_e,
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 @@ static BOOL lsa_io_dom_query_2(const char *desc, DOM_QUERY_2 *d_q, prs_struct *p
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 @@ static void init_lsa_sid_enum(TALLOC_CTX *mem_ctx, LSA_SID_ENUM *sen,
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 @@ static BOOL lsa_io_sid_enum(const char *desc, LSA_SID_ENUM *sen, prs_struct *ps,
/* 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 @@ static BOOL lsa_io_trans_names(const char *desc, LSA_TRANS_NAME_ENUM *trn,
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 @@ void init_q_lookup_names(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_NAMES *q_l,
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 @@ BOOL lsa_io_q_lookup_names(const char *desc, LSA_Q_LOOKUP_NAMES *q_r,
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 @@ BOOL lsa_io_r_lookup_names(const char *desc, LSA_R_LOOKUP_NAMES *r_r,
}
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 @@ BOOL lsa_io_r_enum_privs(const char *desc, LSA_R_ENUM_PRIVS *r_q, prs_struct *ps
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 @@ BOOL lsa_io_r_enum_privsaccount(const char *desc, LSA_R_ENUMPRIVSACCOUNT *r_c, p
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 @@ BOOL lsa_io_q_addprivs(const char *desc, LSA_Q_ADDPRIVS *r_c, prs_struct *ps, in
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 @@ BOOL lsa_io_q_removeprivs(const char *desc, LSA_Q_REMOVEPRIVS *r_c, prs_struct *
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 --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c
index c6f05df0c4..17a8f624ae 100644
--- a/source3/rpc_parse/parse_misc.c
+++ b/source3/rpc_parse/parse_misc.c
@@ -552,18 +552,14 @@ void init_unistr(UNISTR *str, const char *buf)
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 @@ BOOL smb_io_unistr(const char *desc, UNISTR *uni, prs_struct *ps, int depth)
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 @@ BOOL smb_io_buffer3(const char *desc, BUFFER3 *buf3, prs_struct *ps, int depth)
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 @@ void init_buffer2(BUFFER2 *str, const uint8 *buf, size_t len)
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 @@ void copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
(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 copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
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 @@ void init_string2(STRING2 *str, const char *buf, int max_len, int str_len)
/* 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 @@ void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags)
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(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags)
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 @@ void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
str->offset = 0;
str->uni_str_len = len;
- if (max_len < MAX_UNISTRLEN)
- max_len = MAX_UNISTRLEN;
+ alloc_len = MAX((len + 1), MAX_UNISTRLEN);
- alloc_len = (max_len + 1) * sizeof(uint16);
-
- 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 @@ void init_unistr2_from_unistr(UNISTR2 *to, const UNISTR *from)
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 @@ BOOL init_unistr2_array(UNISTR2_ARRAY *array,
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 @@ BOOL smb_io_unistr2_array(const char *desc, UNISTR2_ARRAY *array, prs_struct *ps
}
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 @@ BOOL smb_io_pol_hnd(const char *desc, POLICY_HND *pol, prs_struct *ps, int depth
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 @@ void init_unistr3(UNISTR3 *str, const char *buf)
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 --git a/source3/rpc_parse/parse_net.c b/source3/rpc_parse/parse_net.c
index 813316177a..97ca0d406b 100644
--- a/source3/rpc_parse/parse_net.c
+++ b/source3/rpc_parse/parse_net.c
@@ -1019,7 +1019,7 @@ static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsi
}
/* 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 @@ static BOOL net_io_id_info_ctr(const char *desc, NET_ID_INFO_CTR **pp_ctr, prs_s
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 @@ void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
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 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
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 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
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 @@ BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
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 @@ static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * inf
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 @@ static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * inf
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 @@ static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * inf
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 @@ static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * inf
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 @@ static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
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 @@ static BOOL net_io_sam_privs_info(const char *desc, SAM_DELTA_PRIVS *info,
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 @@ BOOL net_io_r_sam_sync(const char *desc, uint8 sess_key[16],
}
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 @@ BOOL net_io_r_sam_sync(const char *desc, uint8 sess_key[16],
}
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 @@ BOOL net_io_r_sam_deltas(const char *desc, uint8 sess_key[16],
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 @@ BOOL net_io_r_sam_deltas(const char *desc, uint8 sess_key[16],
}
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 --git a/source3/rpc_parse/parse_prs.c b/source3/rpc_parse/parse_prs.c
index c70011c648..67a9d96e19 100644
--- a/source3/rpc_parse/parse_prs.c
+++ b/source3/rpc_parse/parse_prs.c
@@ -105,7 +105,7 @@ BOOL prs_init(prs_struct *ps, uint32 size, TALLOC_CTX *ctx, BOOL io)
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 @@ void prs_mem_clear(prs_struct *ps)
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 @@ BOOL prs_set_buffer_size(prs_struct *ps, uint32 newsize)
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 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
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 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
*/
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 @@ BOOL prs_force_grow(prs_struct *ps, uint32 extra_space)
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 @@ BOOL prs_buffer5(BOOL charmode, const char *name, prs_struct *ps, int depth, BUF
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 @@ BOOL prs_buffer2(BOOL charmode, const char *name, prs_struct *ps, int depth, BUF
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 @@ BOOL prs_string2(BOOL charmode, const char *name, prs_struct *ps, int depth, STR
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 @@ BOOL prs_unistr2(BOOL charmode, const char *name, prs_struct *ps, int depth, UNI
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 @@ BOOL prs_unistr3(BOOL charmode, const char *name, UNISTR3 *str, prs_struct *ps,
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 @@ BOOL prs_unistr(const char *name, prs_struct *ps, int depth, UNISTR *str)
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 --git a/source3/rpc_parse/parse_samr.c b/source3/rpc_parse/parse_samr.c
index ddae4bbdff..34f48b9ad7 100644
--- a/source3/rpc_parse/parse_samr.c
+++ b/source3/rpc_parse/parse_samr.c
@@ -1401,8 +1401,8 @@ BOOL samr_io_r_enum_dom_users(const char *desc, SAMR_R_ENUM_DOM_USERS * r_u,
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 @@ NTSTATUS init_sam_dispinfo_1(TALLOC_CTX *ctx, SAM_DISPINFO_1 *sam, uint32 num_en
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 @@ static BOOL sam_io_sam_dispinfo_1(const char *desc, SAM_DISPINFO_1 * sam,
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 @@ NTSTATUS init_sam_dispinfo_2(TALLOC_CTX *ctx, SAM_DISPINFO_2 *sam, uint32 num_en
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 @@ static BOOL sam_io_sam_dispinfo_2(const char *desc, SAM_DISPINFO_2 * sam,
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 @@ NTSTATUS init_sam_dispinfo_3(TALLOC_CTX *ctx, SAM_DISPINFO_3 *sam, uint32 num_en
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 @@ static BOOL sam_io_sam_dispinfo_3(const char *desc, SAM_DISPINFO_3 * sam,
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 @@ NTSTATUS init_sam_dispinfo_4(TALLOC_CTX *ctx, SAM_DISPINFO_4 *sam, uint32 num_en
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 @@ static BOOL sam_io_sam_dispinfo_4(const char *desc, SAM_DISPINFO_4 * sam,
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 @@ NTSTATUS init_sam_dispinfo_5(TALLOC_CTX *ctx, SAM_DISPINFO_5 *sam, uint32 num_en
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 @@ static BOOL sam_io_sam_dispinfo_5(const char *desc, SAM_DISPINFO_5 * sam,
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 @@ static BOOL samr_group_info_ctr(const char *desc, GROUP_INFO_CTR **ctr,
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 @@ BOOL samr_io_r_query_groupmem(const char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
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 @@ BOOL samr_io_r_query_groupmem(const char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
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 @@ BOOL samr_io_gids(const char *desc, uint32 *num_gids, DOM_GID ** gid,
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 @@ BOOL samr_io_r_enum_domains(const char *desc, SAMR_R_ENUM_DOMAINS * r_u,
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 @@ BOOL samr_io_r_enum_dom_groups(const char *desc, SAMR_R_ENUM_DOM_GROUPS * r_u,
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 @@ BOOL samr_io_r_enum_dom_aliases(const char *desc, SAMR_R_ENUM_DOM_ALIASES * r_u,
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 @@ BOOL samr_io_q_query_useraliases(const char *desc, SAMR_Q_QUERY_USERALIASES * q_
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 @@ BOOL samr_io_rids(const char *desc, uint32 *num_rids, uint32 **rid,
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 @@ void init_samr_q_lookup_rids(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_RIDS * q_u,
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 @@ BOOL samr_io_q_lookup_rids(const char *desc, SAMR_Q_LOOKUP_RIDS * q_u,
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 @@ BOOL samr_io_r_lookup_rids(const char *desc, SAMR_R_LOOKUP_RIDS * r_u,
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 @@ BOOL samr_io_r_lookup_rids(const char *desc, SAMR_R_LOOKUP_RIDS * r_u,
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 @@ BOOL samr_io_r_query_aliasmem(const char *desc, SAMR_R_QUERY_ALIASMEM * r_u,
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 @@ BOOL samr_io_r_query_aliasmem(const char *desc, SAMR_R_QUERY_ALIASMEM * r_u,
}
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 @@ NTSTATUS init_samr_q_lookup_names(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_NAMES * q_u,
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 @@ BOOL samr_io_q_lookup_names(const char *desc, SAMR_Q_LOOKUP_NAMES * q_u,
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 @@ NTSTATUS init_samr_r_lookup_names(TALLOC_CTX *ctx, SAMR_R_LOOKUP_NAMES * r_u,
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 @@ BOOL samr_io_r_lookup_names(const char *desc, SAMR_R_LOOKUP_NAMES * r_u,
}
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 @@ BOOL samr_io_r_lookup_names(const char *desc, SAMR_R_LOOKUP_NAMES * r_u,
}
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 @@ NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
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 @@ NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
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 @@ NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
}
#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 @@ NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
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 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
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 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
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 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
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 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
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 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
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 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
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 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
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 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
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 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
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 @@ BOOL samr_io_q_set_domain_info(const char *desc, SAMR_Q_SET_DOMAIN_INFO *q_u,
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 --git a/source3/rpc_parse/parse_sec.c b/source3/rpc_parse/parse_sec.c
index a78627650a..8656b8f5d8 100644
--- a/source3/rpc_parse/parse_sec.c
+++ b/source3/rpc_parse/parse_sec.c
@@ -129,7 +129,7 @@ BOOL sec_io_acl(const char *desc, SEC_ACL **ppsa, prs_struct *ps, int depth)
/*
* 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 @@ BOOL sec_io_acl(const char *desc, SEC_ACL **ppsa, prs_struct *ps, int depth)
* 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 @@ BOOL sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
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 @@ BOOL sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
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 @@ BOOL sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
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 @@ BOOL sec_io_desc_buf(const char *desc, SEC_DESC_BUF **ppsdb, prs_struct *ps, int
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 --git a/source3/rpc_parse/parse_spoolss.c b/source3/rpc_parse/parse_spoolss.c
index 6362dcf0f1..2e5244d653 100644
--- a/source3/rpc_parse/parse_spoolss.c
+++ b/source3/rpc_parse/parse_spoolss.c
@@ -269,7 +269,7 @@ static BOOL smb_io_notify_option_type_ctr(const char *desc, SPOOL_NOTIFY_OPTION_
/* 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 @@ BOOL smb_io_notify_info_data_strings(const char *desc,SPOOL_NOTIFY_INFO_DATA *da
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 @@ BOOL smb_io_notify_info_data_strings(const char *desc,SPOOL_NOTIFY_INFO_DATA *da
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 @@ BOOL smb_io_notify_info_data_strings(const char *desc,SPOOL_NOTIFY_INFO_DATA *da
/* 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 @@ BOOL spoolss_io_devmode(const char *desc, prs_struct *ps, int depth, DEVICEMODE
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 @@ BOOL spoolss_io_devmode(const char *desc, prs_struct *ps, int depth, DEVICEMODE
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 @@ BOOL spoolss_io_devmode(const char *desc, prs_struct *ps, int depth, DEVICEMODE
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 @@ static BOOL spoolss_io_devmode_cont(const char *desc, DEVMODE_CTR *dm_c, prs_str
/* 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 @@ BOOL make_spoolss_printer_info_2(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2
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 @@ BOOL make_spoolss_printer_info_3(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_3
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 @@ BOOL make_spoolss_printer_info_7(TALLOC_CTX *mem_ctx, SPOOL_PRINTER_INFO_LEVEL_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 @@ BOOL spoolss_io_r_getprinterdata(const char *desc, SPOOL_R_GETPRINTERDATA *r_u,
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 @@ BOOL spoolss_io_q_writeprinter(const char *desc, SPOOL_Q_WRITEPRINTER *q_u, prs_
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 @@ BOOL spoolss_io_q_rffpcnex(const char *desc, SPOOL_Q_RFFPCNEX *q_u, prs_struct *
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 @@ BOOL spoolss_io_q_rfnpcnex(const char *desc, SPOOL_Q_RFNPCNEX *q_u, prs_struct *
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 @@ static BOOL smb_io_relarraystr(const char *desc, NEW_BUFFER *buffer, int depth,
/* 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 @@ static BOOL smb_io_relarraystr(const char *desc, NEW_BUFFER *buffer, int depth,
/* 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 @@ static BOOL smb_io_relarraystr(const char *desc, NEW_BUFFER *buffer, int depth,
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 @@ static BOOL smb_io_reldevmode(const char *desc, NEW_BUFFER *buffer, int depth, D
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 @@ static BOOL spoolss_io_buffer(const char *desc, prs_struct *ps, int depth, NEW_B
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 @@ BOOL make_spoolss_q_setprinter(TALLOC_CTX *mem_ctx, SPOOL_Q_SETPRINTER *q_u,
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 @@ BOOL make_spoolss_q_setprinter(TALLOC_CTX *mem_ctx, SPOOL_Q_SETPRINTER *q_u,
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 @@ BOOL spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il,
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 @@ BOOL spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il,
*/
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 @@ BOOL spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il,
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 @@ BOOL spool_io_printer_info_level(const char *desc, SPOOL_PRINTER_INFO_LEVEL *il,
}
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 @@ BOOL spool_io_printer_driver_info_level_3(const char *desc, SPOOL_PRINTER_DRIVER
/* 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 @@ BOOL spool_io_printer_driver_info_level_6(const char *desc, SPOOL_PRINTER_DRIVER
/* 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 @@ static BOOL uniarray_2_dosarray(BUFFER5 *buf5, fstring **ar)
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 make_spoolss_driver_info_3(TALLOC_CTX *mem_ctx,
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 @@ BOOL make_spoolss_buffer5(TALLOC_CTX *mem_ctx, BUFFER5 *buf5, uint32 len, uint16
{
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 @@ BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
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 @@ BOOL uni_2_asc_printer_driver_6(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *uni,
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 @@ BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni,
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 @@ BOOL spoolss_io_r_enumprinterdata(const char *desc, SPOOL_R_ENUMPRINTERDATA *r_u
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 @@ BOOL spoolss_io_r_enumprinterdata(const char *desc, SPOOL_R_ENUMPRINTERDATA *r_u
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 @@ BOOL spoolss_io_q_setprinterdata(const char *desc, SPOOL_Q_SETPRINTERDATA *q_u,
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 @@ static BOOL copy_spool_notify_info_data(SPOOL_NOTIFY_INFO_DATA *dst,
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 @@ static BOOL copy_spool_notify_info(SPOOL_NOTIFY_INFO *dst, SPOOL_NOTIFY_INFO *sr
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 @@ BOOL spoolss_io_r_getprinterdataex(const char *desc, SPOOL_R_GETPRINTERDATAEX *r
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 @@ BOOL spoolss_io_q_setprinterdataex(const char *desc, SPOOL_Q_SETPRINTERDATAEX *q
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 @@ static BOOL spoolss_io_printer_enum_values_ctr(const char *desc, prs_struct *ps,
/* 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 @@ static BOOL spoolss_io_printer_enum_values_ctr(const char *desc, prs_struct *ps,
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 --git a/source3/rpc_parse/parse_srv.c b/source3/rpc_parse/parse_srv.c
index 8313c82c93..84c45b5901 100644
--- a/source3/rpc_parse/parse_srv.c
+++ b/source3/rpc_parse/parse_srv.c
@@ -783,7 +783,7 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
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 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
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 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
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 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
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 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
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 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
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 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
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 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
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 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
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 @@ static BOOL srv_io_srv_share_ctr(const char *desc, SRV_SHARE_INFO_CTR *ctr, prs_
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 @@ static BOOL srv_io_srv_sess_ctr(const char *desc, SRV_SESS_INFO_CTR **pp_ctr, pr
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 @@ static BOOL srv_io_srv_conn_ctr(const char *desc, SRV_CONN_INFO_CTR **pp_ctr, pr
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 @@ static BOOL srv_io_srv_file_ctr(const char *desc, SRV_FILE_INFO_CTR *ctr, prs_st
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 @@ BOOL srv_io_q_net_srv_set_info(const char *desc, SRV_Q_NET_SRV_SET_INFO *q_n,
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,8 +3308,8 @@ BOOL srv_io_r_net_disk_enum(const char *desc, SRV_R_NET_DISK_ENUM *r_n, prs_stru
DISK_INFO *dinfo;
- if(!(dinfo = (DISK_INFO *)prs_alloc_mem(ps, sizeof(*dinfo) * entries_read3)))
- return False;
+ if(!(dinfo = PRS_ALLOC_MEM(ps, DISK_INFO, entries_read3)))
+ return False;
r_n->disk_enum_ctr.disk_info = dinfo;
}
diff --git a/source3/rpc_server/srv_dfs_nt.c b/source3/rpc_server/srv_dfs_nt.c
index a3b06bb6e1..7334eef85b 100644
--- a/source3/rpc_server/srv_dfs_nt.c
+++ b/source3/rpc_server/srv_dfs_nt.c
@@ -81,9 +81,7 @@ WERROR _dfs_add(pipes_struct *p, DFS_Q_DFS_ADD* q_u, DFS_R_DFS_ADD *r_u)
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 @@ static BOOL init_reply_dfs_info_3(TALLOC_CTX *ctx, struct junction_map* j, DFS_I
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 @@ static WERROR init_reply_dfs_ctr(TALLOC_CTX *ctx, uint32 level,
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 @@ static WERROR init_reply_dfs_ctr(TALLOC_CTX *ctx, uint32 level,
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 @@ static WERROR init_reply_dfs_ctr(TALLOC_CTX *ctx, uint32 level,
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 @@ WERROR _dfs_enum(pipes_struct *p, DFS_Q_DFS_ENUM *q_u, DFS_R_DFS_ENUM *r_u)
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 --git a/source3/rpc_server/srv_echo_nt.c b/source3/rpc_server/srv_echo_nt.c
index ddb76b3a21..86fcce28c7 100644
--- a/source3/rpc_server/srv_echo_nt.c
+++ b/source3/rpc_server/srv_echo_nt.c
@@ -44,7 +44,7 @@ void _echo_data(pipes_struct *p, ECHO_Q_ECHO_DATA *q_u,
{
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 @@ void _source_data(pipes_struct *p, ECHO_Q_SOURCE_DATA *q_u,
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 --git a/source3/rpc_server/srv_lsa_ds_nt.c b/source3/rpc_server/srv_lsa_ds_nt.c
index f6e8eed9a9..d0b7a299be 100644
--- a/source3/rpc_server/srv_lsa_ds_nt.c
+++ b/source3/rpc_server/srv_lsa_ds_nt.c
@@ -41,7 +41,7 @@ static NTSTATUS fill_dsrole_dominfo_basic(TALLOC_CTX *ctx, DSROLE_PRIMARY_DOMAIN
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 --git a/source3/rpc_server/srv_lsa_hnd.c b/source3/rpc_server/srv_lsa_hnd.c
index 2ec62e2c57..0f9f239a02 100644
--- a/source3/rpc_server/srv_lsa_hnd.c
+++ b/source3/rpc_server/srv_lsa_hnd.c
@@ -70,7 +70,7 @@ BOOL init_pipe_handle_list(pipes_struct *p, char *pipe_name)
* 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 @@ BOOL create_policy_hnd(pipes_struct *p, POLICY_HND *hnd, void (*free_fn)(void *)
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 --git a/source3/rpc_server/srv_lsa_nt.c b/source3/rpc_server/srv_lsa_nt.c
index 498b83a4c9..fcd574971f 100644
--- a/source3/rpc_server/srv_lsa_nt.c
+++ b/source3/rpc_server/srv_lsa_nt.c
@@ -232,14 +232,12 @@ static void init_lsa_trans_names(TALLOC_CTX *ctx, DOM_R_REF *ref, LSA_TRANS_NAME
/* 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 @@ NTSTATUS _lsa_open_policy2(pipes_struct *p, LSA_Q_OPEN_POL2 *q_u, LSA_R_OPEN_POL
/* 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 @@ NTSTATUS _lsa_open_policy(pipes_struct *p, LSA_Q_OPEN_POL *q_u, LSA_R_OPEN_POL *
}
/* 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 @@ NTSTATUS _lsa_query_info(pipes_struct *p, LSA_Q_QUERY_INFO *q_u, LSA_R_QUERY_INF
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 @@ NTSTATUS _lsa_lookup_sids(pipes_struct *p, LSA_Q_LOOKUP_SIDS *q_u, LSA_R_LOOKUP_
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 @@ NTSTATUS _lsa_lookup_names(pipes_struct *p,LSA_Q_LOOKUP_NAMES *q_u, LSA_R_LOOKUP
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 @@ NTSTATUS _lsa_enum_privs(pipes_struct *p, LSA_Q_ENUM_PRIVS *q_u, LSA_R_ENUM_PRIV
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 @@ NTSTATUS _lsa_enum_accounts(pipes_struct *p, LSA_Q_ENUM_ACCOUNTS *q_u, LSA_R_ENU
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 @@ NTSTATUS _lsa_open_account(pipes_struct *p, LSA_Q_OPENACCOUNT *q_u, LSA_R_OPENAC
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 --git a/source3/rpc_server/srv_netlog_nt.c b/source3/rpc_server/srv_netlog_nt.c
index a3157435f3..2bc0cf301e 100644
--- a/source3/rpc_server/srv_netlog_nt.c
+++ b/source3/rpc_server/srv_netlog_nt.c
@@ -579,7 +579,7 @@ NTSTATUS _net_sam_logon(pipes_struct *p, NET_Q_SAM_LOGON *q_u, NET_R_SAM_LOGON *
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 --git a/source3/rpc_server/srv_pipe.c b/source3/rpc_server/srv_pipe.c
index bcf5eb533f..01e91ce6c5 100644
--- a/source3/rpc_server/srv_pipe.c
+++ b/source3/rpc_server/srv_pipe.c
@@ -775,7 +775,7 @@ BOOL check_bind_req(struct pipes_struct *p, RPC_IFACE* abstract,
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 @@ NTSTATUS rpc_pipe_register_commands(int version, const char *clnt, const char *s
/* 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 @@ NTSTATUS rpc_pipe_register_commands(int version, const char *clnt, const char *s
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 @@ BOOL api_rpcTNP(pipes_struct *p, const char *rpc_name,
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 --git a/source3/rpc_server/srv_pipe_hnd.c b/source3/rpc_server/srv_pipe_hnd.c
index 562b55b8f7..8720a4df68 100644
--- a/source3/rpc_server/srv_pipe_hnd.c
+++ b/source3/rpc_server/srv_pipe_hnd.c
@@ -204,8 +204,7 @@ smb_np_struct *open_rpc_pipe_p(char *pipe_name,
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 @@ static void *make_internal_rpc_pipe_p(char *pipe_name,
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 --git a/source3/rpc_server/srv_reg_nt.c b/source3/rpc_server/srv_reg_nt.c
index a4e3638be6..dc9db47c66 100644
--- a/source3/rpc_server/srv_reg_nt.c
+++ b/source3/rpc_server/srv_reg_nt.c
@@ -97,7 +97,7 @@ static NTSTATUS open_registry_key(pipes_struct *p, POLICY_HND *hnd, REGISTRY_KEY
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 @@ NTSTATUS _reg_info(pipes_struct *p, REG_Q_INFO *q_u, REG_R_INFO *r_u)
/* 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 --git a/source3/rpc_server/srv_samr_nt.c b/source3/rpc_server/srv_samr_nt.c
index 0c52e859ca..5f74df420a 100644
--- a/source3/rpc_server/srv_samr_nt.c
+++ b/source3/rpc_server/srv_samr_nt.c
@@ -137,7 +137,7 @@ static struct samr_info *get_samr_info_by_sid(DOM_SID *psid)
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 @@ static NTSTATUS load_sampwd_entries(struct samr_info *info, uint16 acb_mask, BOO
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 @@ static NTSTATUS load_group_domain_entries(struct samr_info *info, DOM_SID *sid)
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 @@ static NTSTATUS make_user_sam_entry_list(TALLOC_CTX *ctx, SAM_ENTRY **sam_pp, UN
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 @@ static void make_group_sam_entry_list(TALLOC_CTX *ctx, SAM_ENTRY **sam_pp, UNIST
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 @@ static NTSTATUS get_group_domain_entries( TALLOC_CTX *ctx,
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 @@ static NTSTATUS get_alias_entries( TALLOC_CTX *ctx, DOMAIN_GRP **d_grp,
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 @@ NTSTATUS _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u,
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 @@ NTSTATUS _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u,
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 @@ NTSTATUS _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u,
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 @@ NTSTATUS _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u,
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 @@ NTSTATUS _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u,
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 @@ NTSTATUS _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u,
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 @@ static BOOL make_samr_lookup_rids(TALLOC_CTX *ctx, uint32 num_names, fstring nam
*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 @@ NTSTATUS _samr_lookup_rids(pipes_struct *p, SAMR_Q_LOOKUP_RIDS *q_u, SAMR_R_LOOK
}
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 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_
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 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_
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 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_
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 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_
#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 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_
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 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_
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,8 +2020,7 @@ NTSTATUS _samr_query_usergroups(pipes_struct *p, SAMR_Q_QUERY_USERGROUPS *q_u, S
&(sids[i]), &rid))
continue;
- gids = talloc_realloc(p->mem_ctx, gids,
- sizeof(*gids) * (num_gids+1));
+ gids = TALLOC_REALLOC_ARRAY(p->mem_ctx, gids, DOM_GID, num_gids+1);
gids[num_gids].attr=7;
gids[num_gids].g_rid = rid;
num_gids += 1;
@@ -2064,7 +2058,7 @@ NTSTATUS _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SA
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);
@@ -2549,8 +2543,8 @@ static BOOL make_enum_domains(TALLOC_CTX *ctx, SAM_ENTRY **pp_sam,
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;
@@ -3193,7 +3187,7 @@ NTSTATUS _samr_query_useraliases(pipes_struct *p, SAMR_Q_QUERY_USERALIASES *q_u,
!sid_check_is_builtin(&info->sid))
return NT_STATUS_OBJECT_TYPE_MISMATCH;
- members = talloc(p->mem_ctx, sizeof(DOM_SID) * q_u->num_sids1);
+ members = TALLOC_ARRAY(p->mem_ctx, DOM_SID, q_u->num_sids1);
if (members == NULL)
return NT_STATUS_NO_MEMORY;
@@ -3219,8 +3213,7 @@ NTSTATUS _samr_query_useraliases(pipes_struct *p, SAMR_Q_QUERY_USERALIASES *q_u,
if (!sid_peek_check_rid(&info->sid, &aliases[i], &rid))
continue;
- rids = talloc_realloc(p->mem_ctx, rids,
- sizeof(*rids) * (num_groups+1));
+ rids = TALLOC_REALLOC_ARRAY(p->mem_ctx, rids, uint32, num_groups+1);
if (rids == NULL)
return NT_STATUS_NO_MEMORY;
@@ -3264,7 +3257,7 @@ NTSTATUS _samr_query_aliasmem(pipes_struct *p, SAMR_Q_QUERY_ALIASMEM *q_u, SAMR_
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;
@@ -3290,7 +3283,7 @@ static void add_uid_to_array_unique(uid_t uid, uid_t **uids, int *num)
return;
}
- *uids = Realloc(*uids, (*num+1) * sizeof(uid_t));
+ *uids = SMB_REALLOC_ARRAY(*uids, uid_t, *num+1);
if (*uids == NULL)
return;
@@ -3387,8 +3380,8 @@ NTSTATUS _samr_query_groupmem(pipes_struct *p, SAMR_Q_QUERY_GROUPMEM *q_u, SAMR_
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;
@@ -3978,7 +3971,7 @@ NTSTATUS _samr_query_groupinfo(pipes_struct *p, SAMR_Q_QUERY_GROUPINFO *q_u, SAM
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;
@@ -4309,7 +4302,7 @@ NTSTATUS _samr_unknown_2e(pipes_struct *p, SAMR_Q_UNKNOWN_2E *q_u, SAMR_R_UNKNOW
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 --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c
index aba7e6c22f..78b5fb61fa 100644
--- a/source3/rpc_server/srv_spoolss_nt.c
+++ b/source3/rpc_server/srv_spoolss_nt.c
@@ -238,7 +238,7 @@ static SPOOL_NOTIFY_OPTION *dup_spool_notify_option(SPOOL_NOTIFY_OPTION *sp)
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;
@@ -585,7 +585,7 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint3
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);
@@ -733,7 +733,7 @@ static void notify_string(struct spoolss_notify_msg *msg,
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;
@@ -770,7 +770,7 @@ static void notify_system_time(struct spoolss_notify_msg *msg,
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);
@@ -928,7 +928,7 @@ static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MS
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;
}
@@ -946,7 +946,7 @@ static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MS
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;
}
@@ -958,7 +958,7 @@ static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MS
/* 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;
}
@@ -1016,7 +1016,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx )
/* 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 */
@@ -1436,7 +1436,7 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode)
/* bulk copy first */
- d = talloc_memdup(ctx, devmode, sizeof(DEVICEMODE));
+ d = TALLOC_MEMDUP(ctx, devmode, sizeof(DEVICEMODE));
if (!d)
return NULL;
@@ -1444,7 +1444,7 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode)
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;
}
@@ -1452,12 +1452,12 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode)
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;
}
@@ -1894,7 +1894,7 @@ BOOL convert_devicemode(const char *printername, const DEVICEMODE *devmode,
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);
}
@@ -2235,11 +2235,11 @@ static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printe
/* 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;
}
}
@@ -2286,7 +2286,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint
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;
@@ -2294,7 +2294,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint
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;
@@ -2303,7 +2303,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint
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);
@@ -2313,7 +2313,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint
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;
@@ -2322,7 +2322,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint
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
@@ -2341,7 +2341,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint
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;
@@ -2359,7 +2359,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint
*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 );
@@ -2378,7 +2378,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint
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);
@@ -2394,7 +2394,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint
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++) {
@@ -2406,7 +2406,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint
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;
@@ -2420,7 +2420,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint
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++) {
@@ -2495,7 +2495,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO
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;
}
@@ -2517,7 +2517,7 @@ done:
/* 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;
@@ -2764,7 +2764,7 @@ void spoolss_notify_server_name(int snum,
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;
@@ -2799,7 +2799,7 @@ void spoolss_notify_printer_name(int snum,
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;
@@ -2825,7 +2825,7 @@ void spoolss_notify_share_name(int snum,
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;
@@ -2853,7 +2853,7 @@ void spoolss_notify_port_name(int snum,
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;
@@ -2880,7 +2880,7 @@ void spoolss_notify_driver_name(int snum,
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;
@@ -2909,7 +2909,7 @@ void spoolss_notify_comment(int snum,
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;
@@ -2936,7 +2936,7 @@ void spoolss_notify_location(int snum,
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;
@@ -2975,7 +2975,7 @@ void spoolss_notify_sepfile(int snum,
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;
@@ -3002,7 +3002,7 @@ void spoolss_notify_print_processor(int snum,
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;
@@ -3029,7 +3029,7 @@ void spoolss_notify_parameters(int snum,
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;
@@ -3056,7 +3056,7 @@ void spoolss_notify_datatype(int snum,
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;
@@ -3216,7 +3216,7 @@ static void spoolss_notify_username(int snum,
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;
@@ -3256,7 +3256,7 @@ static void spoolss_notify_job_name(int snum,
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;
@@ -3306,7 +3306,7 @@ static void spoolss_notify_job_status_string(int snum,
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;
@@ -3404,7 +3404,7 @@ static void spoolss_notify_submitted_time(int snum,
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;
@@ -3626,7 +3626,7 @@ static BOOL construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY
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
@@ -3682,7 +3682,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue,
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;
}
@@ -3966,7 +3966,7 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p
/* 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;
}
@@ -4160,7 +4160,7 @@ DEVICEMODE *construct_dev_mode(int snum)
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;
}
@@ -4257,7 +4257,7 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 **
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;
}
@@ -4386,7 +4386,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32
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;
@@ -4475,7 +4475,7 @@ static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer,
* 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;
@@ -4559,7 +4559,7 @@ static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint3
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;
@@ -4735,7 +4735,7 @@ static WERROR getprinter_level_0(Printer_entry *print_hnd, int snum, NEW_BUFFER
{
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);
@@ -4768,7 +4768,7 @@ static WERROR getprinter_level_1(Printer_entry *print_hnd, int snum, NEW_BUFFER
{
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);
@@ -4801,7 +4801,7 @@ static WERROR getprinter_level_2(Printer_entry *print_hnd, int snum, NEW_BUFFER
{
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);
@@ -4868,7 +4868,7 @@ static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, NEW_BUFFER
{
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))
@@ -4902,7 +4902,7 @@ static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, NEW_BUFFER
{
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))
@@ -4933,7 +4933,7 @@ static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, NEW_BUFFER
{
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))
@@ -5135,7 +5135,7 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c
/* 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
@@ -5411,7 +5411,7 @@ static WERROR getprinterdriver2_level1(fstring servername, fstring architecture,
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);
@@ -5448,7 +5448,7 @@ static WERROR getprinterdriver2_level2(fstring servername, fstring architecture,
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);
@@ -6434,7 +6434,7 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum,
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;
@@ -6484,7 +6484,7 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum,
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;
@@ -6676,7 +6676,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture
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);
@@ -6755,7 +6755,7 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture
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);
@@ -6835,7 +6835,7 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture
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);
@@ -6988,7 +6988,7 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF
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;
}
@@ -7192,7 +7192,7 @@ static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need
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);
@@ -7212,7 +7212,7 @@ static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need
} 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));
@@ -7291,7 +7291,7 @@ static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need
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;
}
@@ -7310,7 +7310,7 @@ static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need
*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));
@@ -7390,7 +7390,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_
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;
}
@@ -7719,7 +7719,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen
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);
@@ -7887,7 +7887,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S
*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;
@@ -7902,7 +7902,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S
/* 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;
@@ -7923,7 +7923,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S
/* 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;
@@ -7938,7 +7938,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S
/* 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;
@@ -8323,7 +8323,7 @@ static WERROR enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui
{
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;
@@ -8390,7 +8390,7 @@ static WERROR enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered,
{
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;
@@ -8450,7 +8450,7 @@ static WERROR enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint
{
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;
@@ -8482,7 +8482,7 @@ static WERROR enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint
{
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;
@@ -8557,7 +8557,7 @@ static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum,
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;
@@ -8608,7 +8608,7 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum,
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);
@@ -8640,7 +8640,7 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum,
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 );
}
@@ -8818,7 +8818,7 @@ done:
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;
}
@@ -9177,7 +9177,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_
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)));
@@ -9209,7 +9209,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_
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 ));
@@ -9272,7 +9272,7 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name,
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 --git a/source3/rpc_server/srv_srvsvc_nt.c b/source3/rpc_server/srv_srvsvc_nt.c
index 9837ea2a97..af4c94800a 100644
--- a/source3/rpc_server/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srv_srvsvc_nt.c
@@ -522,10 +522,12 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
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)) ) {
@@ -540,10 +542,12 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
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)) ) {
@@ -557,10 +561,12 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
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)) ) {
@@ -574,10 +580,12 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
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)) ) {
@@ -591,10 +599,12 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
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)) ) {
@@ -610,10 +620,12 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
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)) ) {
@@ -627,10 +639,12 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
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)) ) {
@@ -644,10 +658,12 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
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)) ) {
@@ -661,10 +677,12 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
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)) ) {
@@ -678,10 +696,12 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
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)) ) {
@@ -1132,8 +1152,7 @@ static WERROR init_srv_file_info_ctr(pipes_struct *p, SRV_FILE_INFO_CTR *ctr,
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");
@@ -1184,7 +1203,7 @@ net server get info
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;
@@ -1287,7 +1306,7 @@ WERROR _srv_net_conn_enum(pipes_struct *p, SRV_Q_NET_CONN_ENUM *q_u, SRV_R_NET_C
{
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;
@@ -1312,7 +1331,7 @@ WERROR _srv_net_sess_enum(pipes_struct *p, SRV_Q_NET_SESS_ENUM *q_u, SRV_R_NET_S
{
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;
@@ -1795,7 +1814,7 @@ WERROR _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET
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;
@@ -2114,16 +2133,8 @@ WERROR _srv_net_disk_enum(pipes_struct *p, SRV_Q_NET_DISK_ENUM *q_u, SRV_R_NET_D
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))) {
- return WERR_NOMEM;
- }
-
- r_u->disk_enum_ctr.disk_info = dinfo;
+ 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_ptr = r_u->disk_enum_ctr.disk_info ? 1 : 0;
diff --git a/source3/rpc_server/srv_util.c b/source3/rpc_server/srv_util.c
index 2689d89972..802e7673a4 100644
--- a/source3/rpc_server/srv_util.c
+++ b/source3/rpc_server/srv_util.c
@@ -90,7 +90,7 @@ NTSTATUS nt_token_to_group_list(TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid,
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 --git a/source3/rpc_server/srv_wkssvc_nt.c b/source3/rpc_server/srv_wkssvc_nt.c
index 25fa029237..6528e63225 100644
--- a/source3/rpc_server/srv_wkssvc_nt.c
+++ b/source3/rpc_server/srv_wkssvc_nt.c
@@ -65,7 +65,7 @@ NTSTATUS _wks_query_info(pipes_struct *p, WKS_Q_QUERY_INFO *q_u, WKS_R_QUERY_INF
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 --git a/source3/rpcclient/cmd_echo.c b/source3/rpcclient/cmd_echo.c
index fa4e691663..fce8e4c7b8 100644
--- a/source3/rpcclient/cmd_echo.c
+++ b/source3/rpcclient/cmd_echo.c
@@ -60,7 +60,7 @@ static NTSTATUS cmd_echo_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
}
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 @@ static NTSTATUS cmd_echo_sink_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
}
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 --git a/source3/rpcclient/cmd_lsarpc.c b/source3/rpcclient/cmd_lsarpc.c
index d9afde465d..2b8279ccd2 100644
--- a/source3/rpcclient/cmd_lsarpc.c
+++ b/source3/rpcclient/cmd_lsarpc.c
@@ -207,7 +207,7 @@ static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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 --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c
index 6ab08e1991..3bd55aff06 100644
--- a/source3/rpcclient/cmd_samr.c
+++ b/source3/rpcclient/cmd_samr.c
@@ -1238,7 +1238,7 @@ static NTSTATUS cmd_samr_lookup_names(struct cli_state *cli,
/* 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 @@ static NTSTATUS cmd_samr_lookup_rids(struct cli_state *cli,
/* 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 --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
index 4c4704c4ae..0b0d015238 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -1333,7 +1333,7 @@ static BOOL init_drv_info_3_members (
/* 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 @@ static WERROR cmd_spoolss_setprinterdata(struct cli_state *cli,
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 @@ static WERROR cmd_spoolss_rffpcnex(struct cli_state *cli,
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 --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index bac11f7435..e003b86e67 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -59,10 +59,10 @@ static char **completion_fn(const char *text, int start, int end)
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 @@ static char **completion_fn(const char *text, int start, int end)
( 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 @@ static char **completion_fn(const char *text, int start, int end)
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 @@ static void add_command_set(struct cmd_set *cmd_set)
{
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 --git a/source3/sam/idmap.c b/source3/sam/idmap.c
index 3abfb0ae9f..d18157643b 100644
--- a/source3/sam/idmap.c
+++ b/source3/sam/idmap.c
@@ -83,7 +83,7 @@ NTSTATUS smb_register_idmap(int version, const char *name, struct idmap_methods
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 --git a/source3/sam/idmap_tdb.c b/source3/sam/idmap_tdb.c
index 8ab8ec8477..e89a6cf547 100644
--- a/source3/sam/idmap_tdb.c
+++ b/source3/sam/idmap_tdb.c
@@ -487,7 +487,7 @@ static NTSTATUS db_idmap_init( char *params )
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 --git a/source3/smbd/blocking.c b/source3/smbd/blocking.c
index e143999a78..0e71174a2e 100644
--- a/source3/smbd/blocking.c
+++ b/source3/smbd/blocking.c
@@ -106,12 +106,12 @@ BOOL push_blocking_lock_request( char *inbuf, int length, int lock_timeout,
* 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 --git a/source3/smbd/conn.c b/source3/smbd/conn.c
index 34e19a3ca6..6b5942f7f6 100644
--- a/source3/smbd/conn.c
+++ b/source3/smbd/conn.c
@@ -132,7 +132,7 @@ find_again:
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 --git a/source3/smbd/dir.c b/source3/smbd/dir.c
index 2bda42f76d..f721bf3ba8 100644
--- a/source3/smbd/dir.c
+++ b/source3/smbd/dir.c
@@ -407,7 +407,7 @@ int dptr_create(connection_struct *conn, pstring path, BOOL old_handle, BOOL exp
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 @@ void *OpenDir(connection_struct *conn, const char *name, BOOL use_veto)
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 @@ void *OpenDir(connection_struct *conn, const char *name, BOOL use_veto)
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 --git a/source3/smbd/fake_file.c b/source3/smbd/fake_file.c
index fc874dc086..53aac1e036 100644
--- a/source3/smbd/fake_file.c
+++ b/source3/smbd/fake_file.c
@@ -132,7 +132,7 @@ struct _FAKE_FILE_HANDLE *init_fake_file_handle(enum FAKE_FILE_TYPE type)
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 --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c
index 060fbb124d..a21bd69a36 100644
--- a/source3/smbd/fileio.c
+++ b/source3/smbd/fileio.c
@@ -676,7 +676,7 @@ static BOOL setup_write_cache(files_struct *fsp, SMB_OFF_T file_size)
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;
}
@@ -685,7 +685,7 @@ static BOOL setup_write_cache(files_struct *fsp, SMB_OFF_T file_size)
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 --git a/source3/smbd/files.c b/source3/smbd/files.c
index 580dc54545..ecf39c2b54 100644
--- a/source3/smbd/files.c
+++ b/source3/smbd/files.c
@@ -93,7 +93,7 @@ files_struct *file_new(connection_struct *conn)
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 --git a/source3/smbd/ipc.c b/source3/smbd/ipc.c
index 35e670c9fa..9fcd39b500 100644
--- a/source3/smbd/ipc.c
+++ b/source3/smbd/ipc.c
@@ -165,7 +165,7 @@ void send_trans_reply(char *outbuf,
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 @@ int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int
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 @@ int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int
}
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 @@ int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int
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 --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c
index 7d5e0f5ad2..4af11da784 100644
--- a/source3/smbd/lanman.c
+++ b/source3/smbd/lanman.c
@@ -753,7 +753,7 @@ static BOOL api_DosPrintQGetInfo(connection_struct *conn,
*/
*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);
@@ -772,7 +772,7 @@ static BOOL api_DosPrintQGetInfo(connection_struct *conn,
}
if (mdrcnt > 0) {
- *rdata = REALLOC(*rdata,mdrcnt);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
} else {
@@ -781,7 +781,7 @@ static BOOL api_DosPrintQGetInfo(connection_struct *conn,
* 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)) {
@@ -801,7 +801,7 @@ static BOOL api_DosPrintQGetInfo(connection_struct *conn,
*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);
@@ -849,7 +849,7 @@ static BOOL api_DosPrintQEnum(connection_struct *conn, uint16 vuid, char* param,
*/
*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);
@@ -861,17 +861,17 @@ static BOOL api_DosPrintQEnum(connection_struct *conn, uint16 vuid, char* param,
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;
}
@@ -884,7 +884,7 @@ static BOOL api_DosPrintQEnum(connection_struct *conn, uint16 vuid, char* param,
n++;
}
}
- if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+ if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
@@ -903,7 +903,7 @@ static BOOL api_DosPrintQEnum(connection_struct *conn, uint16 vuid, char* param,
*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);
@@ -987,8 +987,7 @@ static int get_server_info(uint32 servertype,
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);
@@ -1234,7 +1233,7 @@ static BOOL api_RNetServerEnum(connection_struct *conn, uint16 vuid, char *param
}
*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 */
@@ -1258,7 +1257,7 @@ static BOOL api_RNetServerEnum(connection_struct *conn, uint16 vuid, char *param
}
*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);
@@ -1295,7 +1294,7 @@ static BOOL api_RNetGroupGetUsers(connection_struct *conn, uint16 vuid, char *pa
*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);
@@ -1441,13 +1440,13 @@ static BOOL api_RNetShareGetInfo(connection_struct *conn,uint16 vuid, char *para
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);
@@ -1514,7 +1513,7 @@ static BOOL api_RNetShareEnum( connection_struct *conn,
}
}
*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 */
@@ -1537,7 +1536,7 @@ static BOOL api_RNetShareEnum( connection_struct *conn,
}
*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);
@@ -1623,7 +1622,7 @@ static BOOL api_RNetShareAdd(connection_struct *conn,uint16 vuid, char *param,ch
} 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);
@@ -1633,7 +1632,7 @@ static BOOL api_RNetShareAdd(connection_struct *conn,uint16 vuid, char *param,ch
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);
@@ -1688,7 +1687,7 @@ static BOOL api_RNetGroupEnum(connection_struct *conn,uint16 vuid, char *param,c
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;
@@ -1710,7 +1709,7 @@ static BOOL api_RNetGroupEnum(connection_struct *conn,uint16 vuid, char *param,c
*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 */
@@ -1748,7 +1747,7 @@ static BOOL api_NetUserGetGroups(connection_struct *conn,uint16 vuid, char *para
NTSTATUS result;
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
/* check it's a supported varient */
@@ -1767,7 +1766,7 @@ static BOOL api_NetUserGetGroups(connection_struct *conn,uint16 vuid, char *para
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 */
@@ -1859,14 +1858,14 @@ static BOOL api_RNetUserEnum(connection_struct *conn,uint16 vuid, char *param,ch
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;
@@ -1929,10 +1928,10 @@ static BOOL api_NetRemoteTOD(connection_struct *conn,uint16 vuid, char *param,ch
{
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 */
@@ -1991,7 +1990,7 @@ static BOOL api_SetUserPassword(connection_struct *conn,uint16 vuid, char *param
memcpy(pass2,p+16,16);
*rparam_len = 4;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
*rdata_len = 0;
@@ -2063,7 +2062,7 @@ static BOOL api_SamOEMChangePassword(connection_struct *conn,uint16 vuid, char *
fstring user;
char *p = param + 2;
*rparam_len = 2;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
*rdata_len = 0;
@@ -2130,7 +2129,7 @@ static BOOL api_RDosPrintJobDel(connection_struct *conn,uint16 vuid, char *param
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)) {
@@ -2193,7 +2192,7 @@ static BOOL api_WPrintQueueCtrl(connection_struct *conn,uint16 vuid, char *param
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);
@@ -2267,7 +2266,7 @@ static BOOL api_PrintJobInfo(connection_struct *conn,uint16 vuid,char *param,cha
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",
@@ -2368,7 +2367,7 @@ static BOOL api_RNetServerGetInfo(connection_struct *conn,uint16 vuid, char *par
}
*rdata_len = mdrcnt;
- *rdata = REALLOC(*rdata,*rdata_len);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
p = *rdata;
p2 = p + struct_len;
@@ -2417,7 +2416,7 @@ static BOOL api_RNetServerGetInfo(connection_struct *conn,uint16 vuid, char *par
*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);
@@ -2444,14 +2443,14 @@ static BOOL api_NetWkstaGetInfo(connection_struct *conn,uint16 vuid, char *param
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 */
@@ -2690,7 +2689,7 @@ static BOOL api_RNetUserGetInfo(connection_struct *conn,uint16 vuid, char *param
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));
@@ -2709,7 +2708,7 @@ static BOOL api_RNetUserGetInfo(connection_struct *conn,uint16 vuid, char *param
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 */
@@ -2856,7 +2855,7 @@ static BOOL api_WWkstaUserLogon(connection_struct *conn,uint16 vuid, char *param
/* 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;
@@ -2895,7 +2894,7 @@ static BOOL api_WWkstaUserLogon(connection_struct *conn,uint16 vuid, char *param
*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);
@@ -2925,7 +2924,7 @@ static BOOL api_WAccessGetUserPerms(connection_struct *conn,uint16 vuid, char *p
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 */
@@ -2978,7 +2977,7 @@ static BOOL api_WPrintJobGetInfo(connection_struct *conn,uint16 vuid, char *para
}
if (mdrcnt > 0) {
- *rdata = REALLOC(*rdata,mdrcnt);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
} else {
@@ -2987,7 +2986,7 @@ static BOOL api_WPrintJobGetInfo(connection_struct *conn,uint16 vuid, char *para
* 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)) {
@@ -3002,7 +3001,7 @@ static BOOL api_WPrintJobGetInfo(connection_struct *conn,uint16 vuid, char *para
}
*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 @@ static BOOL api_WPrintJobEnumerate(connection_struct *conn,uint16 vuid, char *pa
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 @@ static BOOL api_WPrintJobEnumerate(connection_struct *conn,uint16 vuid, char *pa
*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);
@@ -3162,7 +3161,7 @@ static BOOL api_WPrintDestGetInfo(connection_struct *conn,uint16 vuid, char *par
}
else {
if (mdrcnt > 0) {
- *rdata = REALLOC(*rdata,mdrcnt);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
} else {
@@ -3171,7 +3170,7 @@ static BOOL api_WPrintDestGetInfo(connection_struct *conn,uint16 vuid, char *par
* 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);
@@ -3180,7 +3179,7 @@ static BOOL api_WPrintDestGetInfo(connection_struct *conn,uint16 vuid, char *par
}
*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);
@@ -3219,7 +3218,7 @@ static BOOL api_WPrintDestEnum(connection_struct *conn,uint16 vuid, char *param,
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)) {
@@ -3237,7 +3236,7 @@ static BOOL api_WPrintDestEnum(connection_struct *conn,uint16 vuid, char *param,
*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);
@@ -3269,7 +3268,7 @@ static BOOL api_WPrintDriverEnum(connection_struct *conn,uint16 vuid, char *para
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)) {
@@ -3281,7 +3280,7 @@ static BOOL api_WPrintDriverEnum(connection_struct *conn,uint16 vuid, char *para
*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);
@@ -3313,7 +3312,7 @@ static BOOL api_WPrintQProcEnum(connection_struct *conn,uint16 vuid, char *param
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;
@@ -3326,7 +3325,7 @@ static BOOL api_WPrintQProcEnum(connection_struct *conn,uint16 vuid, char *param
*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);
@@ -3358,7 +3357,7 @@ static BOOL api_WPrintPortEnum(connection_struct *conn,uint16 vuid, char *param,
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;
@@ -3372,7 +3371,7 @@ static BOOL api_WPrintPortEnum(connection_struct *conn,uint16 vuid, char *param,
*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);
@@ -3414,7 +3413,7 @@ static BOOL api_RNetSessionEnum(connection_struct *conn,uint16 vuid, char *param
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;
@@ -3438,7 +3437,7 @@ static BOOL api_RNetSessionEnum(connection_struct *conn,uint16 vuid, char *param
*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 */
@@ -3458,7 +3457,7 @@ static BOOL api_TooSmall(connection_struct *conn,uint16 vuid, char *param,char *
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;
@@ -3480,7 +3479,7 @@ static BOOL api_Unsupported(connection_struct *conn,uint16 vuid, char *param,cha
int *rdata_len,int *rparam_len)
{
*rparam_len = 4;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
*rdata_len = 0;
@@ -3587,11 +3586,11 @@ int api_reply(connection_struct *conn,uint16 vuid,char *outbuf,char *data,char *
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 --git a/source3/smbd/mangle_hash.c b/source3/smbd/mangle_hash.c
index 26ddf1b3a3..0067023e61 100644
--- a/source3/smbd/mangle_hash.c
+++ b/source3/smbd/mangle_hash.c
@@ -476,7 +476,7 @@ static BOOL check_cache( char *s, size_t maxlen )
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 @@ static void name_map(char *OutName, BOOL need83, BOOL cache83, int default_case)
/* mangle it into 8.3 */
if (cache83)
- tmp = strdup(OutName);
+ tmp = SMB_STRDUP(OutName);
to_8_3(OutName, default_case);
diff --git a/source3/smbd/mangle_hash2.c b/source3/smbd/mangle_hash2.c
index c6ad1215b0..4896cfb17b 100644
--- a/source3/smbd/mangle_hash2.c
+++ b/source3/smbd/mangle_hash2.c
@@ -153,13 +153,19 @@ static u32 mangle_hash(const char *key, unsigned int length)
*/
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 @@ static void cache_insert(const char *prefix, int length, u32 hash)
free(prefix_cache[i]);
}
- prefix_cache[i] = strndup(prefix, length);
+ prefix_cache[i] = SMB_STRNDUP(prefix, length);
prefix_cache_hashes[i] = hash;
}
diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c
index 6c132897f9..b5ae7486d3 100644
--- a/source3/smbd/msdfs.c
+++ b/source3/smbd/msdfs.c
@@ -189,7 +189,7 @@ static BOOL parse_symlink(char* buf,struct referral** preflist,
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 @@ static BOOL self_ref(char *pathname, struct junction_map *jucn,
*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 @@ BOOL get_referred_path(char *pathname, struct junction_map *jucn,
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 @@ static int setup_ver2_dfs_referral(char* pathname, char** ppdata,
/* 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 @@ static int setup_ver3_dfs_referral(char* pathname, char** ppdata,
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 @@ static BOOL form_junctions(int snum, struct junction_map* jucn, int* jn_count)
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 --git a/source3/smbd/notify.c b/source3/smbd/notify.c
index 9adf827c79..92b86f350c 100644
--- a/source3/smbd/notify.c
+++ b/source3/smbd/notify.c
@@ -178,7 +178,7 @@ BOOL change_notify_set(char *inbuf, files_struct *fsp, connection_struct *conn,
{
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 --git a/source3/smbd/ntquotas.c b/source3/smbd/ntquotas.c
index 555f32d773..8fbf858008 100644
--- a/source3/smbd/ntquotas.c
+++ b/source3/smbd/ntquotas.c
@@ -199,14 +199,14 @@ int vfs_get_user_ntquota_list(files_struct *fsp, SMB_NTQUOTA_LIST **qt_list)
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 @@ void *init_quota_handle(TALLOC_CTX *mem_ctx)
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 --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c
index 42953a1b7a..2395d0d8db 100644
--- a/source3/smbd/nttrans.c
+++ b/source3/smbd/nttrans.c
@@ -58,11 +58,12 @@ static char *nttrans_realloc(char **ptr, size_t size)
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;
@@ -2139,7 +2140,7 @@ static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *ou
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);
@@ -2449,6 +2450,10 @@ static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf,
}
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)));
@@ -2703,15 +2708,21 @@ due to being in oplock break state.\n", (unsigned int)function_code ));
CVAL(inbuf, smb_wct), 19 + (setup_count/2)));
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 --git a/source3/smbd/open.c b/source3/smbd/open.c
index 7cadf5adba..bf3fbf7fec 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -681,7 +681,7 @@ dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (dou
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 --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index 1ffc798b1f..3ebf93e560 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -740,12 +740,12 @@ static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id,
* 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 --git a/source3/smbd/password.c b/source3/smbd/password.c
index eb389d7013..213ef98ea3 100644
--- a/source3/smbd/password.c
+++ b/source3/smbd/password.c
@@ -139,7 +139,7 @@ int register_vuid(auth_serversupplied_info *server_info, DATA_BLOB session_key,
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 @@ void add_session_user(const char *user)
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 @@ BOOL authorise_login(int snum, fstring user, DATA_BLOB password,
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 --git a/source3/smbd/posix_acls.c b/source3/smbd/posix_acls.c
index d30cf62e7c..903b943522 100644
--- a/source3/smbd/posix_acls.c
+++ b/source3/smbd/posix_acls.c
@@ -166,7 +166,7 @@ static char *create_pai_buf(canon_ace *file_ace_list, canon_ace *dir_ace_list, B
*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 @@ static struct pai_val *create_pai_val(char *buf, size_t size)
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 @@ static struct pai_val *create_pai_val(char *buf, size_t size)
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 @@ static struct pai_val *create_pai_val(char *buf, size_t size)
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 @@ static struct pai_val *load_inherited_info(files_struct *fsp)
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 @@ static struct pai_val *load_inherited_info(files_struct *fsp)
/* 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 void free_canon_ace_list( canon_ace *list_head )
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 @@ static BOOL ensure_canon_entry_valid(canon_ace **pp_ace,
}
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 @@ static BOOL ensure_canon_entry_valid(canon_ace **pp_ace,
}
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 @@ static BOOL ensure_canon_entry_valid(canon_ace **pp_ace,
}
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 @@ static BOOL create_canon_ace_lists(files_struct *fsp, SMB_STRUCT_STAT *pst,
* 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 @@ static canon_ace *canonicalise_acl( files_struct *fsp, SMB_ACL_T posix_acl, SMB_
* 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 @@ size_t get_nt_acl(files_struct *fsp, uint32 security_info, SEC_DESC **ppdesc)
num_def_acls = count_canon_ace_list(dir_ace);
/* Allocate the ace list. */
- if ((nt_ace_list = (SEC_ACE *)malloc((num_acls + num_profile_acls + num_def_acls)* sizeof(SEC_ACE))) == NULL) {
+ if ((nt_ace_list = SMB_MALLOC_ARRAY(SEC_ACE,num_acls + num_profile_acls + num_def_acls)) == NULL) {
DEBUG(0,("get_nt_acl: Unable to malloc space for nt_ace_list.\n"));
goto done;
}
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 5be68d9f0a..8adc5c2e66 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -85,8 +85,7 @@ static void free_queued_message(struct pending_message_list *msg)
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 @@ void smbd_process(void)
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 --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index eda523e73a..23657d3f1f 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -899,7 +899,7 @@ int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
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);
@@ -4945,7 +4945,7 @@ int reply_writebmpx(connection_struct *conn, char *inbuf,char *outbuf, int size,
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 --git a/source3/smbd/sec_ctx.c b/source3/smbd/sec_ctx.c
index 8a85792ead..a5411b94a1 100644
--- a/source3/smbd/sec_ctx.c
+++ b/source3/smbd/sec_ctx.c
@@ -154,7 +154,7 @@ int get_current_groups(gid_t gid, int *p_ngroups, gid_t **p_groups)
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 @@ BOOL push_sec_ctx(void)
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 --git a/source3/smbd/session.c b/source3/smbd/session.c
index 91ebaeb830..9a9a0d90b2 100644
--- a/source3/smbd/session.c
+++ b/source3/smbd/session.c
@@ -151,7 +151,7 @@ BOOL session_claim(user_struct *vuser)
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 @@ static int gather_sessioninfo(TDB_CONTEXT *stdb, TDB_DATA kbuf, TDB_DATA dbuf,
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 --git a/source3/smbd/statcache.c b/source3/smbd/statcache.c
index ba37d4927c..cfc5286327 100644
--- a/source3/smbd/statcache.c
+++ b/source3/smbd/statcache.c
@@ -76,7 +76,7 @@ void stat_cache_add( const char *full_orig_name, const char *orig_translated_pat
* translated path.
*/
- translated_path = strdup(orig_translated_path);
+ translated_path = SMB_STRDUP(orig_translated_path);
if (!translated_path)
return;
@@ -88,7 +88,7 @@ void stat_cache_add( const char *full_orig_name, const char *orig_translated_pat
}
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 @@ BOOL stat_cache_lookup(connection_struct *conn, pstring name, pstring dirpath,
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 --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index 4a10511a0e..7269ab9157 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -115,7 +115,7 @@ static BOOL get_ea_value(TALLOC_CTX *mem_ctx, connection_struct *conn, files_str
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 @@ static struct ea_list *get_ea_list(TALLOC_CTX *mem_ctx, connection_struct *conn,
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 @@ static struct ea_list *get_ea_list(TALLOC_CTX *mem_ctx, connection_struct *conn,
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;
@@ -672,7 +672,7 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
}
/* 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;
@@ -1418,7 +1418,7 @@ close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
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));
@@ -1426,7 +1426,7 @@ close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
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;
@@ -1438,7 +1438,7 @@ close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
/* 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);
}
@@ -1617,7 +1617,7 @@ resume_key = %d resume name = %s continue=%d level = %d\n",
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);
@@ -1625,7 +1625,7 @@ resume_key = %d resume name = %s continue=%d level = %d\n",
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);
@@ -1836,7 +1836,7 @@ static int call_trans2qfsinfo(connection_struct *conn, char *inbuf, char *outbuf
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);
@@ -2519,13 +2519,13 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
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;
@@ -3302,7 +3302,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char
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;
@@ -4028,7 +4028,7 @@ static int call_trans2mkdir(connection_struct *conn, char *inbuf, char *outbuf,
}
/* 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;
@@ -4068,7 +4068,7 @@ static int call_trans2findnotifyfirst(connection_struct *conn, char *inbuf, char
}
/* 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;
@@ -4101,7 +4101,7 @@ static int call_trans2findnotifynext(connection_struct *conn, char *inbuf, char
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;
@@ -4168,7 +4168,7 @@ static int call_trans2ioctl(connection_struct *conn, char* inbuf, char* outbuf,
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;
@@ -4319,9 +4319,9 @@ int reply_trans2(connection_struct *conn,
/* 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 --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 10599c50a1..0102739fe3 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -188,7 +188,7 @@ NTSTATUS smb_register_vfs(int version, const char *name, vfs_op_tuple *vfs_op_tu
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;
@@ -261,7 +261,7 @@ BOOL vfs_init_custom(connection_struct *conn, const char *vfs_object)
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);
@@ -684,7 +684,7 @@ static void array_promote(char *array,int elsize,int element)
if (element == 0)
return;
- p = (char *)malloc(elsize);
+ p = (char *)SMB_MALLOC(elsize);
if (!p) {
DEBUG(5,("array_promote: malloc fail\n"));
@@ -879,7 +879,7 @@ BOOL reduce_name(connection_struct *conn, const pstring fname)
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 --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c
index ceecbcb05d..45895d2ec7 100644
--- a/source3/tdb/tdb.c
+++ b/source3/tdb/tdb.c
@@ -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 --git a/source3/tdb/tdbback.c b/source3/tdb/tdbback.c
index 68b6fadc88..3f5bf3891b 100644
--- a/source3/tdb/tdbback.c
+++ b/source3/tdb/tdbback.c
@@ -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 --git a/source3/tdb/tdbutil.c b/source3/tdb/tdbutil.c
index e57eccfe59..45ebdae3af 100644
--- a/source3/tdb/tdbutil.c
+++ b/source3/tdb/tdbutil.c
@@ -554,7 +554,7 @@ int tdb_unpack(char *buf, int bufsize, const char *fmt, ...)
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 @@ TDB_LIST_NODE *tdb_search_keys(TDB_CONTEXT *tdb, const char* pattern)
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 @@ TDB_LIST_NODE *tdb_search_keys(TDB_CONTEXT *tdb, const char* pattern)
/* 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 --git a/source3/utils/net.c b/source3/utils/net.c
index 784612fc71..251e94db90 100644
--- a/source3/utils/net.c
+++ b/source3/utils/net.c
@@ -144,7 +144,7 @@ NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip,
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_to_ipc_anonymous(struct cli_state **c,
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 @@ BOOL net_find_server(unsigned flags, struct in_addr *server_ip, char **server_na
{
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 @@ BOOL net_find_server(unsigned flags, struct in_addr *server_ip, char **server_na
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 @@ BOOL net_find_server(unsigned flags, struct in_addr *server_ip, char **server_na
} 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 @@ BOOL net_find_server(unsigned flags, struct in_addr *server_ip, char **server_na
} 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 @@ static struct functable net_func[] = {
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 --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c
index 9efa45e58f..72e8f70a7d 100644
--- a/source3/utils/net_ads.c
+++ b/source3/utils/net_ads.c
@@ -259,10 +259,10 @@ static BOOL usergrp_display(char *field, void **values, void *data_area)
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 @@ int net_ads_join(int argc, const char **argv)
}
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 --git a/source3/utils/net_cache.c b/source3/utils/net_cache.c
index a955916458..6bbab1c817 100644
--- a/source3/utils/net_cache.c
+++ b/source3/utils/net_cache.c
@@ -101,7 +101,7 @@ static time_t parse_timeout(const char* timeout_str)
/* 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 --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c
index 35892e8b52..b4f4cdb0a8 100644
--- a/source3/utils/net_idmap.c
+++ b/source3/utils/net_idmap.c
@@ -126,7 +126,7 @@ static NTSTATUS net_idmap_fixup_hwm(void)
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 --git a/source3/utils/net_rap.c b/source3/utils/net_rap.c
index cae0a7f7da..6e8f0d088d 100644
--- a/source3/utils/net_rap.c
+++ b/source3/utils/net_rap.c
@@ -198,7 +198,7 @@ static int rap_share_add(int argc, const char **argv)
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 --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c
index a488affe26..4c5544aa97 100644
--- a/source3/utils/net_rpc.c
+++ b/source3/utils/net_rpc.c
@@ -884,7 +884,7 @@ rpc_user_info_internals(const DOM_SID *domain_sid, const char *domain_name,
/* 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 @@ rpc_share_migrate_files_internals(const DOM_SID *domain_sid, const char *domain_
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 struct full_alias *server_aliases;
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 @@ rpc_fetch_domain_aliases(struct cli_state *cli, TALLOC_CTX *mem_ctx,
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 @@ static void init_user_token(NT_USER_TOKEN *token, DOM_SID *user_sid)
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 @@ static void add_sid_to_token(NT_USER_TOKEN *token, DOM_SID *sid)
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 @@ static BOOL get_user_tokens(int *num_tokens, struct user_token **user_tokens)
*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 @@ static BOOL get_user_tokens_from_file(FILE *f,
/* 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 @@ static void collect_share(const char *name, uint32 m,
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 --git a/source3/utils/net_rpc_join.c b/source3/utils/net_rpc_join.c
index cb8a5ee4d4..79c632f831 100644
--- a/source3/utils/net_rpc_join.c
+++ b/source3/utils/net_rpc_join.c
@@ -258,7 +258,7 @@ int net_rpc_join_newstyle(int argc, const char **argv)
{
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 --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c
index 25f3ab5184..456a29287f 100644
--- a/source3/utils/net_rpc_printer.c
+++ b/source3/utils/net_rpc_printer.c
@@ -501,7 +501,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx,
}
/* 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 @@ get_printer_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* 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))
@@ -2299,7 +2299,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const
}
/* 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) */
@@ -2461,7 +2461,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const
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 --git a/source3/utils/net_rpc_samsync.c b/source3/utils/net_rpc_samsync.c
index 2e7c053ac3..b31087927a 100644
--- a/source3/utils/net_rpc_samsync.c
+++ b/source3/utils/net_rpc_samsync.c
@@ -595,7 +595,7 @@ fetch_group_mem_info(uint32 rid, SAM_GROUP_MEM_INFO *delta)
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 --git a/source3/utils/net_status.c b/source3/utils/net_status.c
index 21e6bffb2c..d584597273 100644
--- a/source3/utils/net_status.c
+++ b/source3/utils/net_status.c
@@ -129,8 +129,7 @@ static int collect_pid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
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 --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c
index 3d51523831..3d55c37355 100644
--- a/source3/utils/ntlm_auth.c
+++ b/source3/utils/ntlm_auth.c
@@ -238,7 +238,7 @@ static BOOL get_require_membership_sid(void) {
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 @@ NTSTATUS contact_winbind_auth_crap(const char *username,
}
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 @@ static void manage_squid_ntlmssp_request(enum stdio_helper_mode stdio_helper_mod
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 @@ static void manage_client_ntlmssp_request(enum stdio_helper_mode stdio_helper_mo
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 @@ static void offer_gss_spnego_mechs(void) {
/* 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 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
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 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
}
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 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
}
*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 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
&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 @@ static BOOL manage_client_krb5_init(SPNEGO_DATA spnego)
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 @@ static void manage_gss_spnego_client_request(enum stdio_helper_mode stdio_helper
/* 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 --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c
index 1eb6a135c5..2e8d0d6d96 100644
--- a/source3/utils/pdbedit.c
+++ b/source3/utils/pdbedit.c
@@ -429,10 +429,10 @@ static int new_user (struct pdb_context *in, const char *username,
}
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 --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c
index b12bf4d35d..048ec8dc3e 100644
--- a/source3/utils/smbcacls.c
+++ b/source3/utils/smbcacls.c
@@ -325,7 +325,7 @@ static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace)
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 @@ static SEC_DESC *sec_desc_parse(char *str)
}
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 @@ static SEC_DESC *sec_desc_parse(char *str)
}
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 --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c
index cbe1bd448f..00f6a74f2f 100644
--- a/source3/utils/smbtree.c
+++ b/source3/utils/smbtree.c
@@ -51,7 +51,7 @@ static void add_name(const char *machine_name, uint32 server_type,
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 --git a/source3/web/cgi.c b/source3/web/cgi.c
index cf309c364e..937e603f8c 100644
--- a/source3/web/cgi.c
+++ b/source3/web/cgi.c
@@ -59,7 +59,7 @@ static char *grab_line(FILE *f, int *cl)
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 @@ void cgi_load_variables(void)
*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 @@ void cgi_load_variables(void)
*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 @@ void cgi_load_variables(void)
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 @@ static BOOL cgi_handle_authorization(char *line)
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 @@ void cgi_setup(const char *rootdir, int auth_required)
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 --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c
index aa285745d6..ca671822d8 100644
--- a/source3/web/neg_lang.c
+++ b/source3/web/neg_lang.c
@@ -85,7 +85,7 @@ void web_set_lang(const char *lang_string)
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 @@ void web_set_lang(const char *lang_string)
} 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 --git a/source3/web/statuspage.c b/source3/web/statuspage.c
index 953222c2fc..57b5d0f7b7 100644
--- a/source3/web/statuspage.c
+++ b/source3/web/statuspage.c
@@ -61,14 +61,14 @@ static void addPid2Machine (pid_t pid, char *machine)
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);
}