summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-12-03 07:20:30 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:06:20 -0500
commit6e6374cb5bcffb4df8bdb0a83327fff92b61ac84 (patch)
treefa45bc8c1a7281492f39069e5edd86da6d0c5d4e /source4
parente5ce904ddbd6175ba86ed827bf096b76b11b5511 (diff)
downloadsamba-6e6374cb5bcffb4df8bdb0a83327fff92b61ac84.tar.gz
samba-6e6374cb5bcffb4df8bdb0a83327fff92b61ac84.tar.bz2
samba-6e6374cb5bcffb4df8bdb0a83327fff92b61ac84.zip
r4055: fixed more places to use type safe allocation macros
(This used to be commit eec698254f67365f27b4b7569fa982e22472aca1)
Diffstat (limited to 'source4')
-rw-r--r--source4/auth/pampass.c10
-rw-r--r--source4/client/client.c4
-rw-r--r--source4/include/smb_interfaces.h2
-rw-r--r--source4/lib/gencache.c5
-rw-r--r--source4/lib/netif/interface.c2
-rw-r--r--source4/lib/registry/common/reg_interface.c4
-rw-r--r--source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c16
-rw-r--r--source4/lib/registry/tools/regshell.c4
-rw-r--r--source4/lib/replace.c2
-rw-r--r--source4/lib/util_file.c2
-rw-r--r--source4/lib/util_getent.c12
-rw-r--r--source4/lib/wins_srv.c2
-rw-r--r--source4/lib/xfile.c2
-rw-r--r--source4/libads/ldap.c12
-rw-r--r--source4/libcli/auth/clikrb5.c4
-rw-r--r--source4/libcli/auth/spnego_parse.c2
-rw-r--r--source4/libcli/ldap/ldap.c9
-rw-r--r--source4/libcli/nmblib.c4
-rw-r--r--source4/libcli/raw/raweas.c4
-rw-r--r--source4/libcli/raw/rawnotify.c3
-rw-r--r--source4/librpc/rpc/dcerpc.c4
-rw-r--r--source4/ntvfs/cifs/vfs_cifs.c2
-rw-r--r--source4/param/loadparm.c2
-rw-r--r--source4/rpc_server/spoolss/dcesrv_spoolss.c2
-rw-r--r--source4/smb_server/nttrans.c2
-rw-r--r--source4/smb_server/trans2.c2
-rw-r--r--source4/torture/basic/aliases.c4
-rw-r--r--source4/torture/nbench/nbio.c2
-rw-r--r--source4/torture/raw/mkdir.c2
-rw-r--r--source4/torture/raw/open.c2
-rw-r--r--source4/utils/setntacl.c2
31 files changed, 64 insertions, 67 deletions
diff --git a/source4/auth/pampass.c b/source4/auth/pampass.c
index a5c9a5de16..8612aa9ac0 100644
--- a/source4/auth/pampass.c
+++ b/source4/auth/pampass.c
@@ -130,7 +130,7 @@ static int smb_pam_conv(int num_msg,
return PAM_CONV_ERR;
}
- reply = malloc(sizeof(struct pam_response) * num_msg);
+ reply = malloc_array_p(struct pam_response, num_msg);
if (!reply)
return PAM_CONV_ERR;
@@ -210,7 +210,7 @@ static struct chat_struct *make_pw_chat(char *p)
struct chat_struct *t;
while (1) {
- t = (struct chat_struct *)malloc(sizeof(*t));
+ t = malloc_p(struct chat_struct);
if (!t) {
DEBUG(0,("make_pw_chat: malloc failed!\n"));
return NULL;
@@ -289,7 +289,7 @@ static int smb_pam_passchange_conv(int num_msg,
return PAM_CONV_ERR;
}
- reply = malloc(sizeof(struct pam_response) * num_msg);
+ reply = malloc_array_p(struct pam_response, num_msg);
if (!reply) {
DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n"));
free_pw_chat(pw_chat);
@@ -405,8 +405,8 @@ static void smb_free_pam_conv(struct pam_conv *pconv)
static struct pam_conv *smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr, const char *user,
const char *passwd, const char *newpass)
{
- struct pam_conv *pconv = (struct pam_conv *)malloc(sizeof(struct pam_conv));
- struct smb_pam_userdata *udp = (struct smb_pam_userdata *)malloc(sizeof(struct smb_pam_userdata));
+ struct pam_conv *pconv = malloc_p(struct pam_conv);
+ struct smb_pam_userdata *udp = malloc_p(struct smb_pam_userdata);
if (pconv == NULL || udp == NULL) {
SAFE_FREE(pconv);
diff --git a/source4/client/client.c b/source4/client/client.c
index e4a7dc7cb5..dae24ce927 100644
--- a/source4/client/client.c
+++ b/source4/client/client.c
@@ -2593,7 +2593,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 = malloc_array_p(char *, MAX_COMPLETIONS);
if (!info.matches) return NULL;
info.matches[0] = NULL;
@@ -2673,7 +2673,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 = malloc_array_p(char *, MAX_COMPLETIONS);
if (!matches) return NULL;
matches[0] = NULL;
diff --git a/source4/include/smb_interfaces.h b/source4/include/smb_interfaces.h
index 5d31f0c6c5..bc5c43f59a 100644
--- a/source4/include/smb_interfaces.h
+++ b/source4/include/smb_interfaces.h
@@ -1644,7 +1644,7 @@ struct smb_notify {
struct {
uint32_t num_changes;
- struct {
+ struct notify_changes {
uint32_t action;
WIRE_STRING name;
} *changes;
diff --git a/source4/lib/gencache.c b/source4/lib/gencache.c
index f32db598f8..160367cfe9 100644
--- a/source4/lib/gencache.c
+++ b/source4/lib/gencache.c
@@ -253,8 +253,7 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout)
time_t t;
unsigned i;
- v = (char*)malloc(sizeof(char) *
- (databuf.dsize - TIMEOUT_LEN));
+ v = malloc_array_p(char, databuf.dsize - TIMEOUT_LEN);
SAFE_FREE(databuf.dptr);
sscanf(entry_buf, CACHE_DATA_FMT, (int*)&i, v);
@@ -338,7 +337,7 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time
}
entry = strndup(databuf.dptr, databuf.dsize);
SAFE_FREE(databuf.dptr);
- valstr = (char*)malloc(sizeof(char) * (databuf.dsize - TIMEOUT_LEN));
+ valstr = malloc_array_p(char, databuf.dsize - TIMEOUT_LEN);
sscanf(entry, CACHE_DATA_FMT, (int*)(&i), valstr);
timeout = i;
diff --git a/source4/lib/netif/interface.c b/source4/lib/netif/interface.c
index 3555170123..c73a2e3d7b 100644
--- a/source4/lib/netif/interface.c
+++ b/source4/lib/netif/interface.c
@@ -83,7 +83,7 @@ static void add_interface(struct in_addr ip, struct in_addr nmask)
return;
}
- iface = (struct interface *)malloc(sizeof(*iface));
+ iface = malloc_p(struct interface);
if (!iface) return;
ZERO_STRUCTPN(iface);
diff --git a/source4/lib/registry/common/reg_interface.c b/source4/lib/registry/common/reg_interface.c
index dea8861745..f7d3af0705 100644
--- a/source4/lib/registry/common/reg_interface.c
+++ b/source4/lib/registry/common/reg_interface.c
@@ -51,7 +51,7 @@ NTSTATUS registry_register(const void *_function)
return NT_STATUS_OBJECT_NAME_COLLISION;
}
- entry = malloc(sizeof(struct reg_init_function_entry));
+ entry = malloc_p(struct reg_init_function_entry);
entry->functions = functions;
DLIST_ADD(backends, entry);
@@ -85,7 +85,7 @@ WERROR reg_create(struct registry_context **_ret)
TALLOC_CTX *mem_ctx;
struct registry_context *ret;
mem_ctx = talloc_init("registry handle");
- ret = talloc(mem_ctx, sizeof(struct registry_context));
+ ret = talloc_p(mem_ctx, struct registry_context);
ret->mem_ctx = mem_ctx;
ZERO_STRUCTP(ret);
*_ret = ret;
diff --git a/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c b/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c
index aac6e548a8..381f0c3bcf 100644
--- a/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c
+++ b/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c
@@ -540,7 +540,7 @@ static SEC_DESC *nt_create_def_sec_desc(struct registry_hive *regf)
{
SEC_DESC *tmp;
- tmp = (SEC_DESC *)malloc(sizeof(SEC_DESC));
+ tmp = malloc_p(SEC_DESC);
tmp->revision = 1;
tmp->type = SEC_DESC_SELF_RELATIVE | SEC_DESC_DACL_PRESENT;
@@ -577,7 +577,7 @@ static KEY_SEC_DESC *nt_create_init_sec(struct registry_hive *h)
REGF *regf = h->backend_data;
KEY_SEC_DESC *tsec = NULL;
- tsec = (KEY_SEC_DESC *)malloc(sizeof(KEY_SEC_DESC));
+ tsec = malloc_p(KEY_SEC_DESC);
tsec->ref_cnt = 1;
tsec->state = SEC_DESC_NBK;
@@ -682,7 +682,7 @@ static SK_MAP *alloc_sk_map_entry(struct registry_hive *h, KEY_SEC_DESC *tmp, in
{
REGF *regf = h->backend_data;
if (!regf->sk_map) { /* Allocate a block of 10 */
- regf->sk_map = (SK_MAP *)malloc(sizeof(SK_MAP) * 10);
+ regf->sk_map = malloc_array_p(SK_MAP, 10);
regf->sk_map_size = 10;
regf->sk_count = 1;
(regf->sk_map)[0].sk_off = sk_off;
@@ -742,7 +742,7 @@ static KEY_SEC_DESC *lookup_create_sec_key(struct registry_hive *h, SK_MAP *sk_m
return tmp;
}
else { /* Allocate a new one */
- tmp = (KEY_SEC_DESC *)malloc(sizeof(KEY_SEC_DESC));
+ tmp = malloc_p(KEY_SEC_DESC);
memset(tmp, 0, sizeof(KEY_SEC_DESC)); /* Neatly sets offset to 0 */
tmp->state = SEC_DESC_RES;
if (!alloc_sk_map_entry(h, tmp, sk_off)) {
@@ -756,7 +756,7 @@ static SEC_DESC *process_sec_desc(struct registry_hive *regf, SEC_DESC *sec_desc
{
SEC_DESC *tmp = NULL;
- tmp = (SEC_DESC *)malloc(sizeof(SEC_DESC));
+ tmp = malloc_p(SEC_DESC);
tmp->revision = SVAL(&sec_desc->revision,0);
tmp->type = SVAL(&sec_desc->type,0);
@@ -838,7 +838,7 @@ static KEY_SEC_DESC *process_sk(struct registry_hive *regf, SK_HDR *sk_hdr, int
*/
if (!tmp) {
- tmp = (KEY_SEC_DESC *)malloc(sizeof(KEY_SEC_DESC));
+ tmp = malloc_p(KEY_SEC_DESC);
memset(tmp, 0, sizeof(KEY_SEC_DESC));
/*
@@ -1154,7 +1154,7 @@ static HBIN_BLK *nt_create_hbin_blk(struct registry_hive *h, int size)
size = (size + (REGF_HDR_BLKSIZ - 1)) & ~(REGF_HDR_BLKSIZ - 1);
- tmp = (HBIN_BLK *)malloc(sizeof(HBIN_BLK));
+ tmp = malloc_p(HBIN_BLK);
memset(tmp, 0, sizeof(HBIN_BLK));
tmp->data = malloc(size);
@@ -1553,7 +1553,7 @@ static REGF_HDR *nt_get_reg_header(struct registry_hive *h) {
REGF *regf = h->backend_data;
HBIN_BLK *tmp = NULL;
- tmp = (HBIN_BLK *)malloc(sizeof(HBIN_BLK));
+ tmp = malloc_p(HBIN_BLK);
memset(tmp, 0, sizeof(HBIN_BLK));
tmp->type = REG_OUTBLK_HDR;
diff --git a/source4/lib/registry/tools/regshell.c b/source4/lib/registry/tools/regshell.c
index 3333299088..f18b012720 100644
--- a/source4/lib/registry/tools/regshell.c
+++ b/source4/lib/registry/tools/regshell.c
@@ -247,7 +247,7 @@ static char **reg_complete_command(const char *text, int end)
char **matches;
int i, len, samelen=0, count=1;
- matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
+ matches = malloc_array_p(char *, MAX_COMPLETIONS);
if (!matches) return NULL;
matches[0] = NULL;
@@ -301,7 +301,7 @@ static char **reg_complete_key(const char *text, int end)
TALLOC_CTX *mem_ctx;
/* Complete argument */
- matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
+ matches = malloc_array_p(char *, MAX_COMPLETIONS);
if (!matches) return NULL;
matches[0] = NULL;
diff --git a/source4/lib/replace.c b/source4/lib/replace.c
index 35e0277c59..ca367da9b5 100644
--- a/source4/lib/replace.c
+++ b/source4/lib/replace.c
@@ -205,7 +205,7 @@ Corrections by richard.kettlewell@kewill.com
struct group *g;
char *gr;
- if((grouplst = (gid_t *)malloc(sizeof(gid_t) * max_gr)) == NULL) {
+ if((grouplst = malloc_array_p(gid_t, max_gr)) == NULL) {
DEBUG(0,("initgroups: malloc fail !\n"));
return -1;
}
diff --git a/source4/lib/util_file.c b/source4/lib/util_file.c
index f9697fb337..2b2fe2b2af 100644
--- a/source4/lib/util_file.c
+++ b/source4/lib/util_file.c
@@ -281,7 +281,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 = malloc_array_p(char *, i+2);
if (!ret) {
SAFE_FREE(p);
return NULL;
diff --git a/source4/lib/util_getent.c b/source4/lib/util_getent.c
index 599e4bb917..9f58472fb8 100644
--- a/source4/lib/util_getent.c
+++ b/source4/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 = malloc_p(struct sys_grent);
if (gent == NULL) {
DEBUG (0, ("Out of memory in getgrent_list!\n"));
return NULL;
@@ -67,7 +67,7 @@ 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 = malloc_array_p(char *, num+1)) == NULL)
goto err;
memset(gent->gr_mem, '\0', (num+1) * sizeof(char *));
@@ -80,7 +80,7 @@ struct sys_grent * getgrent_list(void)
grp = getgrent();
if (grp) {
- gent->next = (struct sys_grent *) malloc(sizeof(struct sys_grent));
+ gent->next = 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 = malloc_p(struct sys_pwent);
if (pent == NULL) {
DEBUG (0, ("Out of memory in getpwent_list!\n"));
return NULL;
@@ -170,7 +170,7 @@ struct sys_pwent * getpwent_list(void)
pwd = getpwent();
if (pwd) {
- pent->next = (struct sys_pwent *) malloc(sizeof(struct sys_pwent));
+ pent->next = malloc_p(struct sys_pwent);
if (pent->next == NULL)
goto err;
pent = pent->next;
@@ -223,7 +223,7 @@ 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 = malloc_p(struct sys_userlist);
if (entry == NULL) {
free_userlist(list_head);
return NULL;
diff --git a/source4/lib/wins_srv.c b/source4/lib/wins_srv.c
index 094de8d6b0..0338db8b3d 100644
--- a/source4/lib/wins_srv.c
+++ b/source4/lib/wins_srv.c
@@ -204,7 +204,7 @@ 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 = malloc_array_p(char *, 2);
if (!ret) return NULL;
ret[0] = strdup("*");
ret[1] = NULL;
diff --git a/source4/lib/xfile.c b/source4/lib/xfile.c
index 856e5dd6e6..794e3f0f5e 100644
--- a/source4/lib/xfile.c
+++ b/source4/lib/xfile.c
@@ -96,7 +96,7 @@ XFILE *x_fopen(const char *fname, int flags, mode_t mode)
{
XFILE *ret;
- ret = (XFILE *)malloc(sizeof(XFILE));
+ ret = malloc_p(XFILE);
if (!ret) return NULL;
memset(ret, 0, sizeof(XFILE));
diff --git a/source4/libads/ldap.c b/source4/libads/ldap.c
index d4b363cae6..cd551af7f0 100644
--- a/source4/libads/ldap.c
+++ b/source4/libads/ldap.c
@@ -276,7 +276,7 @@ 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;
@@ -317,7 +317,7 @@ static char **ads_push_strvals(TALLOC_CTX *ctx, const char **in_vals)
if (!in_vals) return NULL;
for (i=0; in_vals[i]; i++); /* count values */
- values = (char ** ) talloc_zero(ctx, (i+1)*sizeof(char *));
+ values = talloc_zero_array_p(ctx, char *, i+1);
if (!values) return NULL;
for (i=0; in_vals[i]; i++) {
@@ -336,7 +336,7 @@ static char **ads_pull_strvals(TALLOC_CTX *ctx, const char **in_vals)
if (!in_vals) return NULL;
for (i=0; in_vals[i]; i++); /* count values */
- values = (char **) talloc_zero(ctx, (i+1)*sizeof(char *));
+ values = talloc_zero_array_p(ctx, char *, i+1);
if (!values) return NULL;
for (i=0; in_vals[i]; i++) {
@@ -758,11 +758,11 @@ 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_p(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;
+ }
return mods;
}
@@ -804,7 +804,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) {
diff --git a/source4/libcli/auth/clikrb5.c b/source4/libcli/auth/clikrb5.c
index 48e1f88503..7ad8dd7b6c 100644
--- a/source4/libcli/auth/clikrb5.c
+++ b/source4/libcli/auth/clikrb5.c
@@ -212,7 +212,7 @@
return -1;
}
- sa = malloc( sizeof(struct sockaddr) * num_kdcs );
+ sa = malloc_array_p(struct sockaddr, num_kdcs);
if (!sa) {
DEBUG(0, ("krb5_locate_kdc: malloc failed\n"));
krb5_krbhst_free(ctx, hnd);
@@ -220,7 +220,7 @@
return -1;
}
- *addr_pp = malloc(sizeof(struct sockaddr) * num_kdcs);
+ *addr_pp = malloc_array_p(struct sockaddr, num_kdcs);
memset(*addr_pp, '\0', sizeof(struct sockaddr) * num_kdcs );
for (i = 0; i < num_kdcs && (rc = krb5_krbhst_next(ctx, hnd, &hinfo) == 0); i++) {
diff --git a/source4/libcli/auth/spnego_parse.c b/source4/libcli/auth/spnego_parse.c
index 825b0a78d2..2cf38728a9 100644
--- a/source4/libcli/auth/spnego_parse.c
+++ b/source4/libcli/auth/spnego_parse.c
@@ -49,7 +49,7 @@ static BOOL read_negTokenInit(struct asn1_data *asn1, struct spnego_negTokenInit
asn1_start_tag(asn1, ASN1_CONTEXT(0));
asn1_start_tag(asn1, ASN1_SEQUENCE(0));
- token->mechTypes = talloc(NULL, sizeof(*token->mechTypes));
+ token->mechTypes = talloc_p(NULL, const char *);
for (i = 0; !asn1->has_error &&
0 < asn1_tag_remaining(asn1); i++) {
token->mechTypes =
diff --git a/source4/libcli/ldap/ldap.c b/source4/libcli/ldap/ldap.c
index dd689027f9..076d088ee2 100644
--- a/source4/libcli/ldap/ldap.c
+++ b/source4/libcli/ldap/ldap.c
@@ -130,7 +130,7 @@ static struct ldap_parse_tree *ldap_parse_simple(TALLOC_CTX *mem_ctx,
if (val && strchr("()&|", *val))
return NULL;
- ret = talloc(mem_ctx, sizeof(*ret));
+ ret = talloc_p(mem_ctx, struct ldap_parse_tree);
if (!ret) {
errno = ENOMEM;
return NULL;
@@ -157,8 +157,7 @@ static struct ldap_parse_tree *ldap_parse_filterlist(TALLOC_CTX *mem_ctx,
{
struct ldap_parse_tree *ret, *next;
- ret = talloc(mem_ctx, sizeof(*ret));
-
+ ret = talloc_p(mem_ctx, struct ldap_parse_tree);
if (!ret) {
errno = ENOMEM;
return NULL;
@@ -166,7 +165,7 @@ static struct ldap_parse_tree *ldap_parse_filterlist(TALLOC_CTX *mem_ctx,
ret->operation = op;
ret->u.list.num_elements = 1;
- ret->u.list.elements = talloc(mem_ctx, sizeof(*ret->u.list.elements));
+ ret->u.list.elements = talloc_p(mem_ctx, struct ldap_parse_tree *);
if (!ret->u.list.elements) {
errno = ENOMEM;
return NULL;
@@ -206,7 +205,7 @@ static struct ldap_parse_tree *ldap_parse_not(TALLOC_CTX *mem_ctx, const char *s
{
struct ldap_parse_tree *ret;
- ret = talloc(mem_ctx, sizeof(*ret));
+ ret = talloc_p(mem_ctx, struct ldap_parse_tree);
if (!ret) {
errno = ENOMEM;
return NULL;
diff --git a/source4/libcli/nmblib.c b/source4/libcli/nmblib.c
index 70c6fab8da..0a3f72ba74 100644
--- a/source4/libcli/nmblib.c
+++ b/source4/libcli/nmblib.c
@@ -333,7 +333,7 @@ static BOOL parse_alloc_res_rec(char *inbuf,int *offset,int length,
struct res_rec **recs, int count)
{
int i;
- *recs = (struct res_rec *)malloc(sizeof(**recs)*count);
+ *recs = malloc_array_p(struct res_rec, count);
if (!*recs) return(False);
memset((char *)*recs,'\0',sizeof(**recs)*count);
@@ -523,7 +523,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 = malloc_p(struct packet_struct)) == NULL)
{
DEBUG(0,("copy_nmb_packet: malloc fail.\n"));
return NULL;
diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c
index 621181841f..027705b381 100644
--- a/source4/libcli/raw/raweas.c
+++ b/source4/libcli/raw/raweas.c
@@ -174,7 +174,7 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob,
blob2.data = blob->data + ofs;
blob2.length = ea_size - ofs;
- *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1));
+ *eas = talloc_realloc_p(mem_ctx, *eas, struct ea_struct, n+1);
if (! *eas) return NT_STATUS_NO_MEMORY;
len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]);
@@ -219,7 +219,7 @@ NTSTATUS ea_pull_list_chained(const DATA_BLOB *blob,
blob2.data = blob->data + ofs + 4;
blob2.length = blob->length - (ofs + 4);
- *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1));
+ *eas = talloc_realloc_p(mem_ctx, *eas, struct ea_struct, n+1);
if (! *eas) return NT_STATUS_NO_MEMORY;
len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]);
diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c
index ea5fada1ee..918fb788cb 100644
--- a/source4/libcli/raw/rawnotify.c
+++ b/source4/libcli/raw/rawnotify.c
@@ -73,8 +73,7 @@ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req,
}
/* allocate array */
- parms->out.changes = talloc(mem_ctx, sizeof(parms->out.changes[0]) *
- parms->out.num_changes);
+ parms->out.changes = talloc_array_p(mem_ctx, struct notify_changes, parms->out.num_changes);
if (!parms->out.changes) {
return NT_STATUS_NO_MEMORY;
}
diff --git a/source4/librpc/rpc/dcerpc.c b/source4/librpc/rpc/dcerpc.c
index 3526c0adf9..7cd18d2807 100644
--- a/source4/librpc/rpc/dcerpc.c
+++ b/source4/librpc/rpc/dcerpc.c
@@ -541,7 +541,7 @@ NTSTATUS dcerpc_bind(struct dcerpc_pipe *p,
pkt.u.bind.max_recv_frag = 5840;
pkt.u.bind.assoc_group_id = 0;
pkt.u.bind.num_contexts = 1;
- pkt.u.bind.ctx_list = talloc(mem_ctx, sizeof(pkt.u.bind.ctx_list[0]));
+ pkt.u.bind.ctx_list = talloc_p(mem_ctx, struct dcerpc_ctx_list);
if (!pkt.u.bind.ctx_list) {
return NT_STATUS_NO_MEMORY;
}
@@ -620,7 +620,7 @@ NTSTATUS dcerpc_alter(struct dcerpc_pipe *p,
pkt.u.alter.max_recv_frag = 0x2000;
pkt.u.alter.assoc_group_id = 0;
pkt.u.alter.num_contexts = 1;
- pkt.u.alter.ctx_list = talloc(mem_ctx, sizeof(pkt.u.alter.ctx_list[0]));
+ pkt.u.alter.ctx_list = talloc_p(mem_ctx, struct dcerpc_ctx_list);
if (!pkt.u.alter.ctx_list) {
return NT_STATUS_NO_MEMORY;
}
diff --git a/source4/ntvfs/cifs/vfs_cifs.c b/source4/ntvfs/cifs/vfs_cifs.c
index bfba31b46f..736aa3652f 100644
--- a/source4/ntvfs/cifs/vfs_cifs.c
+++ b/source4/ntvfs/cifs/vfs_cifs.c
@@ -121,7 +121,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
return NT_STATUS_INVALID_PARAMETER;
}
- private = talloc(req->tcon, sizeof(struct cvfs_private));
+ private = talloc_p(req->tcon, struct cvfs_private);
if (!private) {
return NT_STATUS_NO_MEMORY;
}
diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c
index 8975f066fa..334ec982e0 100644
--- a/source4/param/loadparm.c
+++ b/source4/param/loadparm.c
@@ -2185,7 +2185,7 @@ static void init_copymap(service * pservice)
{
int i;
SAFE_FREE(pservice->copymap);
- pservice->copymap = (BOOL *)malloc(sizeof(BOOL) * NUMPARAMETERS);
+ pservice->copymap = malloc_array_p(BOOL, NUMPARAMETERS);
if (!pservice->copymap)
DEBUG(0,
("Couldn't allocate copymap!! (size %d)\n",
diff --git a/source4/rpc_server/spoolss/dcesrv_spoolss.c b/source4/rpc_server/spoolss/dcesrv_spoolss.c
index 17c23dcba8..25210913fe 100644
--- a/source4/rpc_server/spoolss/dcesrv_spoolss.c
+++ b/source4/rpc_server/spoolss/dcesrv_spoolss.c
@@ -168,7 +168,7 @@ static WERROR spoolss_EnumPrinters(struct dcesrv_call_state *dce_call, TALLOC_CT
goto done;
}
- r->out.buffer = (DATA_BLOB *)talloc(mem_ctx, sizeof(DATA_BLOB));
+ r->out.buffer = talloc_p(mem_ctx, DATA_BLOB);
if (!r->out.buffer) {
result = WERR_NOMEM;
diff --git a/source4/smb_server/nttrans.c b/source4/smb_server/nttrans.c
index 0a268ccbf4..31391b88c1 100644
--- a/source4/smb_server/nttrans.c
+++ b/source4/smb_server/nttrans.c
@@ -383,7 +383,7 @@ void reply_nttrans(struct smbsrv_request *req)
}
/* parse out the setup words */
- trans.in.setup = talloc(req, trans.in.setup_count * sizeof(uint16_t));
+ trans.in.setup = talloc_array_p(req, uint16_t, trans.in.setup_count);
if (!trans.in.setup) {
req_reply_error(req, NT_STATUS_NO_MEMORY);
return;
diff --git a/source4/smb_server/trans2.c b/source4/smb_server/trans2.c
index 427583954a..8f995e2f6a 100644
--- a/source4/smb_server/trans2.c
+++ b/source4/smb_server/trans2.c
@@ -1350,7 +1350,7 @@ void reply_trans_generic(struct smbsrv_request *req, uint8_t command)
}
/* parse out the setup words */
- trans.in.setup = talloc(req, trans.in.setup_count * sizeof(uint16_t));
+ trans.in.setup = talloc_array_p(req, uint16_t, trans.in.setup_count);
if (trans.in.setup_count && !trans.in.setup) {
req_reply_error(req, NT_STATUS_NO_MEMORY);
return;
diff --git a/source4/torture/basic/aliases.c b/source4/torture/basic/aliases.c
index ba4bf69f13..50aabb825a 100644
--- a/source4/torture/basic/aliases.c
+++ b/source4/torture/basic/aliases.c
@@ -48,7 +48,7 @@ static void gen_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int lev
status = smb_raw_trans2(cli->tree, mem_ctx, t2);
if (!NT_STATUS_IS_OK(status)) continue;
- t2b = talloc(mem_ctx, sizeof(*t2b));
+ t2b = talloc_p(mem_ctx, struct trans2_blobs);
t2b->level = level;
t2b->params = t2->out.params;
t2b->data = t2->out.data;
@@ -278,7 +278,7 @@ static void gen_set_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int
if (!NT_STATUS_IS_OK(status) &&
!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) continue;
- t2b = talloc(mem_ctx, sizeof(*t2b));
+ t2b = talloc_p(mem_ctx, struct trans2_blobs);
t2b->level = level;
t2b->params = t2->out.params;
t2b->data = t2->out.data;
diff --git a/source4/torture/nbench/nbio.c b/source4/torture/nbench/nbio.c
index 34de81c5b3..32bd108442 100644
--- a/source4/torture/nbench/nbio.c
+++ b/source4/torture/nbench/nbio.c
@@ -281,7 +281,7 @@ void nb_createx(const char *fname,
if (!NT_STATUS_IS_OK(ret)) return;
- f = malloc(sizeof(struct ftable));
+ f = malloc_p(struct ftable);
f->handle = handle;
f->fd = io.ntcreatex.out.fnum;
diff --git a/source4/torture/raw/mkdir.c b/source4/torture/raw/mkdir.c
index 2d7fa678e1..539258946a 100644
--- a/source4/torture/raw/mkdir.c
+++ b/source4/torture/raw/mkdir.c
@@ -101,7 +101,7 @@ static BOOL test_mkdir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
/* with EAs */
md.t2mkdir.in.num_eas = 1;
- md.t2mkdir.in.eas = talloc(mem_ctx, sizeof(md.t2mkdir.in.eas[0]));
+ md.t2mkdir.in.eas = talloc_p(mem_ctx, struct ea_struct);
md.t2mkdir.in.eas[0].flags = 0;
md.t2mkdir.in.eas[0].name.s = "EAONE";
md.t2mkdir.in.eas[0].value = data_blob_talloc(mem_ctx, "1", 1);
diff --git a/source4/torture/raw/open.c b/source4/torture/raw/open.c
index fb50ec6c4f..fe0d4fe4fa 100644
--- a/source4/torture/raw/open.c
+++ b/source4/torture/raw/open.c
@@ -499,7 +499,7 @@ static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
io.t2open.in.size = 0;
io.t2open.in.timeout = 0;
- io.t2open.in.eas = talloc(mem_ctx, sizeof(io.t2open.in.eas[0]));
+ io.t2open.in.eas = talloc_p(mem_ctx, struct ea_struct);
io.t2open.in.num_eas = 1;
io.t2open.in.eas[0].flags = 0;
io.t2open.in.eas[0].name.s = "EAONE";
diff --git a/source4/utils/setntacl.c b/source4/utils/setntacl.c
index cd9f262e12..0535c3037e 100644
--- a/source4/utils/setntacl.c
+++ b/source4/utils/setntacl.c
@@ -75,7 +75,7 @@ static void setntacl(char *filename, struct security_descriptor *sd)
fgets(line, sizeof(line), stdin);
sd->group_sid = dom_sid_parse_talloc(mem_ctx, line);
- acl = talloc(mem_ctx, sizeof(struct security_acl));
+ acl = talloc_p(mem_ctx, struct security_acl);
acl->revision = 2;
acl->size = 0;