summaryrefslogtreecommitdiffstats
path: root/source4
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-12-04 09:30:38 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:06:20 -0500
commit2f9e170f45e128eb6ab6bd97c9c8b40dcd9a97fa (patch)
treeb16853d79b72ea2984e8c67c6f7f800ca9ff0807 /source4
parentfbb5a6a0fabd3d7878f2fa95db3eef3e8504b6d2 (diff)
downloadsamba-2f9e170f45e128eb6ab6bd97c9c8b40dcd9a97fa.tar.gz
samba-2f9e170f45e128eb6ab6bd97c9c8b40dcd9a97fa.tar.xz
samba-2f9e170f45e128eb6ab6bd97c9c8b40dcd9a97fa.zip
r4058: added a type safe version of smb_xmalloc()
(This used to be commit 1235afa5fe3a396cd7a180cbc500834a30fbaa80)
Diffstat (limited to 'source4')
-rw-r--r--source4/include/includes.h5
-rw-r--r--source4/lib/registry/tools/regpatch.c8
-rw-r--r--source4/lib/util_pw.c2
-rw-r--r--source4/libads/ads_struct.c2
-rw-r--r--source4/param/loadparm.c9
-rw-r--r--source4/rpc_server/echo/rpc_echo.c2
6 files changed, 16 insertions, 12 deletions
diff --git a/source4/include/includes.h b/source4/include/includes.h
index 6335780b89..ad24ff676d 100644
--- a/source4/include/includes.h
+++ b/source4/include/includes.h
@@ -321,3 +321,8 @@ int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
#endif /* _INCLUDES_H */
+/*
+ type safe varient of smb_xmalloc()
+*/
+#define smb_xmalloc_p(type) (type *)smb_xmalloc(sizeof(type))
+
diff --git a/source4/lib/registry/tools/regpatch.c b/source4/lib/registry/tools/regpatch.c
index a8b2f83ee1..9b37b7952b 100644
--- a/source4/lib/registry/tools/regpatch.c
+++ b/source4/lib/registry/tools/regpatch.c
@@ -154,7 +154,7 @@ static void print_line(struct cmd_line *cl)
*/
static struct cmd_line *get_cmd_line(int fd)
{
- struct cmd_line *cl = (CMD_LINE *)smb_xmalloc(sizeof(CMD_LINE));
+ struct cmd_line *cl = smb_xmalloc_p(CMD_LINE);
int i = 0, rc;
uint8_t ch;
@@ -445,7 +445,7 @@ static CMD *regedit4_get_cmd(int fd)
struct cmd_line *cl = NULL;
struct val_spec_list *vl = NULL;
- cmd = (struct command_s *)smb_xmalloc(sizeof(struct command_s));
+ cmd = smb_xmalloc_p(struct command_s);
cmd->cmd = CMD_NONE;
cmd->key = NULL;
@@ -488,7 +488,7 @@ static CMD *regedit4_get_cmd(int fd)
* There could be a \ on the end which we need to
* handle at some time
*/
- vl = (struct val_spec_list *)smb_xmalloc(sizeof(struct val_spec_list));
+ vl = smb_xmalloc_p(struct val_spec_list);
vl->next = NULL;
vl->val = NULL;
vl->name = parse_value(cl, &vl->type, &vl->val);
@@ -607,7 +607,7 @@ static CMD_FILE *cmd_file_create(const char *file)
return NULL;
}
- tmp = (CMD_FILE *)smb_xmalloc(sizeof(CMD_FILE));
+ tmp = smb_xmalloc_p(CMD_FILE);
/*
* Let's fill in some of the fields;
diff --git a/source4/lib/util_pw.c b/source4/lib/util_pw.c
index 9d075a05e8..19893e396f 100644
--- a/source4/lib/util_pw.c
+++ b/source4/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/source4/libads/ads_struct.c b/source4/libads/ads_struct.c
index 9774968e12..a6c679e002 100644
--- a/source4/libads/ads_struct.c
+++ b/source4/libads/ads_struct.c
@@ -87,7 +87,7 @@ 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;
diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c
index 334ec982e0..035ac3422a 100644
--- a/source4/param/loadparm.c
+++ b/source4/param/loadparm.c
@@ -1576,8 +1576,7 @@ static int add_a_service(const service *pservice, const char *name)
}
else {
ServicePtrs = tsp;
- ServicePtrs[iNumServices] =
- (service *) malloc(sizeof(service));
+ ServicePtrs[iNumServices] = malloc_p(service);
}
if (!ServicePtrs[iNumServices]) {
DEBUG(0,("add_a_service: out of memory!\n"));
@@ -1871,7 +1870,7 @@ static void copy_service(service * pserviceDest, service * pserviceSource, BOOL
pdata = pdata->next;
}
if (not_added) {
- paramo = smb_xmalloc(sizeof(*paramo));
+ paramo = smb_xmalloc_p(struct param_opt);
paramo->key = strdup(data->key);
paramo->value = strdup(data->value);
DLIST_ADD(pserviceDest->param_opt, paramo);
@@ -1940,7 +1939,7 @@ static void add_to_file_list(const char *fname, const char *subfname)
}
if (!f) {
- f = (struct file_lists *)malloc(sizeof(file_lists[0]));
+ f = malloc_p(struct file_lists);
if (!f)
return;
f->next = file_lists;
@@ -2247,7 +2246,7 @@ static BOOL lp_do_parameter_parametric(int snum, const char *pszParmName, const
}
}
- paramo = smb_xmalloc(sizeof(*paramo));
+ paramo = smb_xmalloc_p(struct param_opt);
paramo->key = strdup(name);
paramo->value = strdup(pszParmValue);
paramo->flags = flags;
diff --git a/source4/rpc_server/echo/rpc_echo.c b/source4/rpc_server/echo/rpc_echo.c
index 6e8b94c610..f86ae6debf 100644
--- a/source4/rpc_server/echo/rpc_echo.c
+++ b/source4/rpc_server/echo/rpc_echo.c
@@ -70,7 +70,7 @@ static NTSTATUS echo_TestCall(struct dcesrv_call_state *dce_call, TALLOC_CTX *me
static NTSTATUS echo_TestCall2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall2 *r)
{
- r->out.info = talloc(mem_ctx, sizeof(*r->out.info));
+ r->out.info = talloc_p(mem_ctx, union echo_Info);
if (!r->out.info) {
return NT_STATUS_NO_MEMORY;
}