summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-01-06 02:32:43 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:08:20 -0500
commitcc55aef7c116d03ba2817625b0ba9edb378525e3 (patch)
treee36f5694a422c5b80cb1f631c9dd182994aab9e2
parent66bd6142a2fc4679e1d6cc98237a23927dda5f63 (diff)
downloadsamba-cc55aef7c116d03ba2817625b0ba9edb378525e3.tar.gz
samba-cc55aef7c116d03ba2817625b0ba9edb378525e3.tar.bz2
samba-cc55aef7c116d03ba2817625b0ba9edb378525e3.zip
r4547: - added talloc_new(ctx) macro that is a neater form of the common talloc(ctx, 0) call.
- cleaned up some talloc usage in various files I'd like to get to the point that we have no calls to talloc(), at which point we will rename talloc_p() to talloc(), to encourage everyone to use the typesafe functions. (This used to be commit e6c81d7c9f8a6938947d3c1c8a971a0d6d50b67a)
-rw-r--r--source4/client/client.c8
-rw-r--r--source4/dsdb/samdb/samdb_privilege.c2
-rw-r--r--source4/ldap_server/ldap_parse.c4
-rw-r--r--source4/ldap_server/ldap_server.c4
-rw-r--r--source4/lib/events.c2
-rw-r--r--source4/lib/ldb/ldb_ldap/ldb_ldap.c2
-rw-r--r--source4/lib/talloc/talloc.h1
-rw-r--r--source4/lib/talloc/talloc_guide.txt9
-rw-r--r--source4/lib/talloc/testsuite.c4
-rw-r--r--source4/libcli/clilist.c4
-rw-r--r--source4/libcli/raw/rawfile.c2
-rw-r--r--source4/libcli/util/clilsa.c6
-rw-r--r--source4/ntvfs/common/sidmap.c12
-rw-r--r--source4/ntvfs/posix/pvfs_rename.c2
-rw-r--r--source4/ntvfs/posix/pvfs_xattr.c4
-rw-r--r--source4/ntvfs/posix/xattr_tdb.c4
-rw-r--r--source4/ntvfs/unixuid/vfs_unixuid.c2
-rw-r--r--source4/torture/basic/denytest.c4
-rw-r--r--source4/torture/local/idtree.c2
-rw-r--r--source4/torture/raw/search.c4
-rw-r--r--source4/torture/torture_util.c2
21 files changed, 47 insertions, 37 deletions
diff --git a/source4/client/client.c b/source4/client/client.c
index 62b2042a02..b2255fc7b8 100644
--- a/source4/client/client.c
+++ b/source4/client/client.c
@@ -1899,7 +1899,7 @@ lookup a name or sid
static int cmd_lookup(const char **cmd_ptr)
{
fstring buf;
- TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
NTSTATUS status;
struct dom_sid *sid;
@@ -1943,7 +1943,7 @@ show privileges for a user
static int cmd_privileges(const char **cmd_ptr)
{
fstring buf;
- TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
NTSTATUS status;
struct dom_sid *sid;
struct lsa_RightSet rights;
@@ -1990,7 +1990,7 @@ add privileges for a user
static int cmd_addprivileges(const char **cmd_ptr)
{
fstring buf;
- TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
NTSTATUS status;
struct dom_sid *sid;
struct lsa_RightSet rights;
@@ -2040,7 +2040,7 @@ delete privileges for a user
static int cmd_delprivileges(const char **cmd_ptr)
{
fstring buf;
- TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
NTSTATUS status;
struct dom_sid *sid;
struct lsa_RightSet rights;
diff --git a/source4/dsdb/samdb/samdb_privilege.c b/source4/dsdb/samdb/samdb_privilege.c
index 2a57ff0d74..08435e2731 100644
--- a/source4/dsdb/samdb/samdb_privilege.c
+++ b/source4/dsdb/samdb/samdb_privilege.c
@@ -78,7 +78,7 @@ static NTSTATUS samdb_privilege_setup_sid(void *samctx, TALLOC_CTX *mem_ctx,
NTSTATUS samdb_privilege_setup(struct security_token *token)
{
void *samctx;
- TALLOC_CTX *mem_ctx = talloc(token, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(token);
int i;
NTSTATUS status;
diff --git a/source4/ldap_server/ldap_parse.c b/source4/ldap_server/ldap_parse.c
index 269f51704c..d645d24104 100644
--- a/source4/ldap_server/ldap_parse.c
+++ b/source4/ldap_server/ldap_parse.c
@@ -80,7 +80,7 @@ static void ldap_parse_attributetypedescription(struct ldap_schema *schema, DATA
{
char *desc;
- desc = (char *)talloc(schema, data->lenght + 1);
+ desc = talloc_array_p(schema, char, data->lenght + 1);
memcpy(desc, data->data, data->lenght);
desc[data->lenght] = '\0';
@@ -90,7 +90,7 @@ static void ldap_parse_objectclassdescription(struct ldap_schema *schema, DATA_B
{
char *desc;
- desc = (char *)talloc(schema, data->lenght + 1);
+ desc = talloc_array_p(schema, char, data->lenght + 1);
memcpy(desc, data->data, data->lenght);
desc[data->lenght] = '\0';
diff --git a/source4/ldap_server/ldap_server.c b/source4/ldap_server/ldap_server.c
index 0bace4b690..a301c14084 100644
--- a/source4/ldap_server/ldap_server.c
+++ b/source4/ldap_server/ldap_server.c
@@ -206,7 +206,7 @@ static BOOL ldapsrv_read_buf(struct ldapsrv_connection *conn)
return read_into_buf(sock, &conn->in_buffer);
}
- mem_ctx = talloc(conn, 0);
+ mem_ctx = talloc_new(conn);
if (!mem_ctx) {
DEBUG(0,("no memory\n"));
return False;
@@ -315,7 +315,7 @@ static BOOL ldapsrv_write_buf(struct ldapsrv_connection *conn)
return write_from_buf(sock, &conn->out_buffer);
}
- mem_ctx = talloc(conn, 0);
+ mem_ctx = talloc_new(conn);
if (!mem_ctx) {
DEBUG(0,("no memory\n"));
return False;
diff --git a/source4/lib/events.c b/source4/lib/events.c
index 0ca6b66598..9f28100a26 100644
--- a/source4/lib/events.c
+++ b/source4/lib/events.c
@@ -85,7 +85,7 @@ struct event_context *event_context_init(TALLOC_CTX *mem_ctx)
/* start off with no events */
ZERO_STRUCTP(ev);
- ev->events = talloc(ev, 0);
+ ev->events = talloc_new(ev);
return ev;
}
diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
index fee02da32f..bab3c86e16 100644
--- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c
+++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
@@ -86,7 +86,7 @@ static int lldb_rename(struct ldb_module *module, const char *olddn, const char
int ret = 0;
char *newrdn, *p;
const char *parentdn = "";
- TALLOC_CTX *mem_ctx = talloc(lldb, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(lldb);
/* ignore ltdb specials */
if (olddn[0] == '@' ||newdn[0] == '@') {
diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h
index 9e828f2f0d..ee3e0be8eb 100644
--- a/source4/lib/talloc/talloc.h
+++ b/source4/lib/talloc/talloc.h
@@ -37,6 +37,7 @@ typedef void TALLOC_CTX;
#define talloc_zero(ctx, size) _talloc_zero(ctx, size, __location__)
#define talloc_realloc(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__)
#define talloc_p(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
+#define talloc_new(ctx) talloc_named_const(ctx, 0, "talloc_new: " __location__)
#define talloc_zero_p(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
#define talloc_zero_array_p(ctx, type, count) (type *)talloc_zero_array(ctx, sizeof(type), count, __location__)
#define talloc_array_p(ctx, type, count) (type *)talloc_array(ctx, sizeof(type), count, __location__)
diff --git a/source4/lib/talloc/talloc_guide.txt b/source4/lib/talloc/talloc_guide.txt
index ce3c8bde68..aa37c60466 100644
--- a/source4/lib/talloc/talloc_guide.txt
+++ b/source4/lib/talloc/talloc_guide.txt
@@ -261,6 +261,15 @@ level context. It is equivalent to:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+void *talloc_new(void *ctx);
+
+This is a utility macro that creates a new memory context hanging
+off an exiting context, automatically naming it "talloc_new: __location__"
+where __location__ is the source line it is called from. It is
+particularly useful for creating a new temporary working context.
+
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void *talloc_realloc(const void *context, void *ptr, size_t size);
The talloc_realloc() function changes the size of a talloc
diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c
index 22444b1116..a3a448ef40 100644
--- a/source4/lib/talloc/testsuite.c
+++ b/source4/lib/talloc/testsuite.c
@@ -333,7 +333,7 @@ static BOOL test_misc(void)
printf("TESTING MISCELLANEOUS\n");
- root = talloc(NULL, 0);
+ root = talloc_new(NULL);
p1 = talloc(root, 0x7fffffff);
if (p1) {
@@ -515,7 +515,7 @@ static BOOL test_realloc(void)
printf("TESTING REALLOC\n");
- root = talloc(NULL, 0);
+ root = talloc_new(NULL);
p1 = talloc(root, 10);
CHECK_SIZE(p1, 10);
diff --git a/source4/libcli/clilist.c b/source4/libcli/clilist.c
index 8b05b98e0e..ec103dbfa4 100644
--- a/source4/libcli/clilist.c
+++ b/source4/libcli/clilist.c
@@ -119,7 +119,7 @@ int smbcli_list_new(struct smbcli_tree *tree, const char *Mask, uint16_t attribu
state.dirlist_len = 0;
state.total_received = 0;
- state.dirlist = talloc(state.mem_ctx, 0);
+ state.dirlist = talloc_new(state.mem_ctx);
mask = talloc_strdup(state.mem_ctx, Mask);
if (level == RAW_SEARCH_GENERIC) {
@@ -263,7 +263,7 @@ int smbcli_list_old(struct smbcli_tree *tree, const char *Mask, uint16_t attribu
state.dirlist_len = 0;
state.total_received = 0;
- state.dirlist = talloc(state.mem_ctx, 0);
+ state.dirlist = talloc_new(state.mem_ctx);
mask = talloc_strdup(state.mem_ctx, Mask);
while (1) {
diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c
index 11be8ffba7..e0b54cacc3 100644
--- a/source4/libcli/raw/rawfile.c
+++ b/source4/libcli/raw/rawfile.c
@@ -259,7 +259,7 @@ static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tr
{
struct smb_nttrans nt;
uint8_t *params;
- TALLOC_CTX *mem_ctx = talloc(tree, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(tree);
uint16_t fname_len;
DATA_BLOB sd_blob, ea_blob;
struct smbcli_request *req;
diff --git a/source4/libcli/util/clilsa.c b/source4/libcli/util/clilsa.c
index 4204adcc07..843d45607b 100644
--- a/source4/libcli/util/clilsa.c
+++ b/source4/libcli/util/clilsa.c
@@ -153,7 +153,7 @@ NTSTATUS smblsa_sid_check_privilege(struct smbcli_state *cli,
{
struct lsa_RightSet rights;
NTSTATUS status;
- TALLOC_CTX *mem_ctx = talloc(cli, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(cli);
struct dom_sid *sid;
unsigned i;
@@ -195,7 +195,7 @@ NTSTATUS smblsa_lookup_sid(struct smbcli_state *cli,
uint32_t count = 1;
NTSTATUS status;
struct dom_sid *sid;
- TALLOC_CTX *mem_ctx2 = talloc(mem_ctx, 0);
+ TALLOC_CTX *mem_ctx2 = talloc_new(mem_ctx);
status = smblsa_connect(cli);
if (!NT_STATUS_IS_OK(status)) {
@@ -255,7 +255,7 @@ NTSTATUS smblsa_lookup_name(struct smbcli_state *cli,
uint32_t count = 1;
NTSTATUS status;
struct dom_sid *sid;
- TALLOC_CTX *mem_ctx2 = talloc(mem_ctx, 0);
+ TALLOC_CTX *mem_ctx2 = talloc_new(mem_ctx);
uint32_t rid;
status = smblsa_connect(cli);
diff --git a/source4/ntvfs/common/sidmap.c b/source4/ntvfs/common/sidmap.c
index 89ad2e2430..3254330c2f 100644
--- a/source4/ntvfs/common/sidmap.c
+++ b/source4/ntvfs/common/sidmap.c
@@ -94,7 +94,7 @@ static NTSTATUS sidmap_primary_domain_sid(struct sidmap_context *sidmap,
TALLOC_CTX *mem_ctx, struct dom_sid **sid)
{
const char *attrs[] = { "objectSid", NULL };
- void *ctx = talloc(mem_ctx, 0);
+ void *ctx = talloc_new(mem_ctx);
const char *sidstr;
int ret;
struct ldb_message **res;
@@ -138,7 +138,7 @@ NTSTATUS sidmap_sid_to_unixuid(struct sidmap_context *sidmap,
struct dom_sid *domain_sid;
NTSTATUS status;
- ctx = talloc(sidmap, 0);
+ ctx = talloc_new(sidmap);
sidstr = dom_sid_string(ctx, sid);
if (sidstr == NULL) {
talloc_free(ctx);
@@ -237,7 +237,7 @@ NTSTATUS sidmap_sid_to_unixgid(struct sidmap_context *sidmap,
NTSTATUS status;
struct dom_sid *domain_sid;
- ctx = talloc(sidmap, 0);
+ ctx = talloc_new(sidmap);
sidstr = dom_sid_string(ctx, sid);
if (sidstr == NULL) {
talloc_free(ctx);
@@ -349,7 +349,7 @@ NTSTATUS sidmap_uid_to_sid(struct sidmap_context *sidmap,
*/
- ctx = talloc(sidmap, 0);
+ ctx = talloc_new(sidmap);
/*
@@ -461,7 +461,7 @@ NTSTATUS sidmap_gid_to_sid(struct sidmap_context *sidmap,
*/
- ctx = talloc(sidmap, 0);
+ ctx = talloc_new(sidmap);
/*
@@ -553,7 +553,7 @@ NTSTATUS sidmap_allocated_sid_lookup(struct sidmap_context *sidmap,
{
NTSTATUS status;
struct dom_sid *domain_sid;
- void *ctx = talloc(mem_ctx, 0);
+ void *ctx = talloc_new(mem_ctx);
uint32_t rid;
status = sidmap_primary_domain_sid(sidmap, ctx, &domain_sid);
diff --git a/source4/ntvfs/posix/pvfs_rename.c b/source4/ntvfs/posix/pvfs_rename.c
index f8d0ba1c27..8e057f214b 100644
--- a/source4/ntvfs/posix/pvfs_rename.c
+++ b/source4/ntvfs/posix/pvfs_rename.c
@@ -128,7 +128,7 @@ static NTSTATUS pvfs_rename_one(struct pvfs_state *pvfs,
uint16_t attrib)
{
struct pvfs_filename *name1, *name2;
- TALLOC_CTX *mem_ctx = talloc(req, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(req);
NTSTATUS status;
/* resolve the wildcard pattern for this name */
diff --git a/source4/ntvfs/posix/pvfs_xattr.c b/source4/ntvfs/posix/pvfs_xattr.c
index baa6c15e31..ca535db168 100644
--- a/source4/ntvfs/posix/pvfs_xattr.c
+++ b/source4/ntvfs/posix/pvfs_xattr.c
@@ -127,7 +127,7 @@ static NTSTATUS pvfs_xattr_ndr_save(struct pvfs_state *pvfs,
const char *fname, int fd, const char *attr_name,
void *p, ndr_push_flags_fn_t push_fn)
{
- TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
DATA_BLOB blob;
NTSTATUS status;
@@ -151,7 +151,7 @@ NTSTATUS pvfs_dosattrib_load(struct pvfs_state *pvfs, struct pvfs_filename *name
{
NTSTATUS status;
struct xattr_DosAttrib attrib;
- TALLOC_CTX *mem_ctx = talloc(name, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(name);
struct xattr_DosInfo1 *info1;
struct xattr_DosInfo2 *info2;
diff --git a/source4/ntvfs/posix/xattr_tdb.c b/source4/ntvfs/posix/xattr_tdb.c
index 12fe50c277..eebae38ab7 100644
--- a/source4/ntvfs/posix/xattr_tdb.c
+++ b/source4/ntvfs/posix/xattr_tdb.c
@@ -42,7 +42,7 @@ static NTSTATUS xattr_tdb_add_list(struct pvfs_state *pvfs, const char *attr_nam
return NT_STATUS_OK;
}
- mem_ctx = talloc(pvfs, 0);
+ mem_ctx = talloc_new(pvfs);
status = pull_xattr_blob_tdb(pvfs, mem_ctx, XATTR_LIST_ATTR,
fname, fd, 100, &blob);
@@ -211,7 +211,7 @@ NTSTATUS delete_xattr_tdb(struct pvfs_state *pvfs, const char *attr_name,
*/
NTSTATUS unlink_xattr_tdb(struct pvfs_state *pvfs, const char *fname)
{
- TALLOC_CTX *mem_ctx = talloc(pvfs, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(pvfs);
DATA_BLOB blob;
const char *s;
NTSTATUS status;
diff --git a/source4/ntvfs/unixuid/vfs_unixuid.c b/source4/ntvfs/unixuid/vfs_unixuid.c
index f29ed51a49..a1a5244453 100644
--- a/source4/ntvfs/unixuid/vfs_unixuid.c
+++ b/source4/ntvfs/unixuid/vfs_unixuid.c
@@ -145,7 +145,7 @@ static NTSTATUS unixuid_setup_security(struct ntvfs_module_context *ntvfs,
{
struct unixuid_private *private = ntvfs->private_data;
struct security_token *token = req->session->session_info->security_token;
- void *ctx = talloc(req, 0);
+ void *ctx = talloc_new(req);
struct unix_sec_ctx *newsec;
NTSTATUS status;
diff --git a/source4/torture/basic/denytest.c b/source4/torture/basic/denytest.c
index 0e0032058f..7308805da7 100644
--- a/source4/torture/basic/denytest.c
+++ b/source4/torture/basic/denytest.c
@@ -1812,7 +1812,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c
for (i=0;i<torture_numops;i++) {
NTSTATUS status1, status2, status2_p;
int64_t tdif;
- TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
enum deny_result res, res2;
int b_sa1 = random() & ((1<<nbits1)-1);
int b_am1 = random() & ((1<<nbits2)-1);
@@ -1977,7 +1977,7 @@ BOOL torture_denydos_sharing(void)
return False;
}
- mem_ctx = talloc(cli, 0);
+ mem_ctx = talloc_new(cli);
printf("Checking DENY_DOS shared handle semantics\n");
smbcli_unlink(cli->tree, fname);
diff --git a/source4/torture/local/idtree.c b/source4/torture/local/idtree.c
index 7d0e3e84a8..3f30d7123f 100644
--- a/source4/torture/local/idtree.c
+++ b/source4/torture/local/idtree.c
@@ -31,7 +31,7 @@ BOOL torture_local_idtree(void)
BOOL ret = True;
extern int torture_numops;
int n = torture_numops;
- void *ctx = talloc(NULL, 0);
+ void *ctx = talloc_new(NULL);
idr = idr_init(ctx);
diff --git a/source4/torture/raw/search.c b/source4/torture/raw/search.c
index 5064c1a061..55acaba2b2 100644
--- a/source4/torture/raw/search.c
+++ b/source4/torture/raw/search.c
@@ -635,7 +635,7 @@ static BOOL test_many_files(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
for (t=0;t<ARRAY_SIZE(search_types);t++) {
ZERO_STRUCT(result);
- result.mem_ctx = talloc(mem_ctx, 0);
+ result.mem_ctx = talloc_new(mem_ctx);
printf("Continue %s via %s\n", search_types[t].name, search_types[t].cont_name);
@@ -767,7 +767,7 @@ static BOOL test_modify_search(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
printf("pulling the first file\n");
ZERO_STRUCT(result);
- result.mem_ctx = talloc(mem_ctx, 0);
+ result.mem_ctx = talloc_new(mem_ctx);
io.generic.level = RAW_SEARCH_BOTH_DIRECTORY_INFO;
io.t2ffirst.in.search_attrib = 0;
diff --git a/source4/torture/torture_util.c b/source4/torture/torture_util.c
index de93d6731f..3df1f3be41 100644
--- a/source4/torture/torture_util.c
+++ b/source4/torture/torture_util.c
@@ -363,7 +363,7 @@ NTSTATUS torture_check_ea(struct smbcli_state *cli,
union smb_fileinfo info;
NTSTATUS status;
struct ea_name ea;
- TALLOC_CTX *mem_ctx = talloc(cli, 0);
+ TALLOC_CTX *mem_ctx = talloc_new(cli);
info.ea_list.level = RAW_FILEINFO_EA_LIST;
info.ea_list.file.fname = fname;