r4547: - added talloc_new(ctx) macro that is a neater form of the common talloc(ctx...
authorAndrew Tridgell <tridge@samba.org>
Thu, 6 Jan 2005 02:32:43 +0000 (02:32 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:08:20 +0000 (13:08 -0500)
- 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)

21 files changed:
source4/client/client.c
source4/dsdb/samdb/samdb_privilege.c
source4/ldap_server/ldap_parse.c
source4/ldap_server/ldap_server.c
source4/lib/events.c
source4/lib/ldb/ldb_ldap/ldb_ldap.c
source4/lib/talloc/talloc.h
source4/lib/talloc/talloc_guide.txt
source4/lib/talloc/testsuite.c
source4/libcli/clilist.c
source4/libcli/raw/rawfile.c
source4/libcli/util/clilsa.c
source4/ntvfs/common/sidmap.c
source4/ntvfs/posix/pvfs_rename.c
source4/ntvfs/posix/pvfs_xattr.c
source4/ntvfs/posix/xattr_tdb.c
source4/ntvfs/unixuid/vfs_unixuid.c
source4/torture/basic/denytest.c
source4/torture/local/idtree.c
source4/torture/raw/search.c
source4/torture/torture_util.c

index 62b2042a029f10e63c9fc9663bce7606a37902d8..b2255fc7b85a6e27c8b805c78d0401ab6a50b803 100644 (file)
@@ -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;
index 2a57ff0d7425445e72cc878e3f980fcc1a985990..08435e2731242bcdb31d0aa2b8495568bf2e0739 100644 (file)
@@ -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;
 
index 269f51704cce0f2d4ad68787d5221344c67c1fcb..d645d24104560c774728da8f13ee2d553ae005e4 100644 (file)
@@ -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';
 
index 0bace4b690a35dad388b98cd44ca2785dd50a148..a301c14084ea019044af0a28fd95f62c9cd852d5 100644 (file)
@@ -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;
index 0ca6b665986d9726b76d6512c985b715e5580dd2..9f28100a268ea12a1f7cc836a7e6bd1305151324 100644 (file)
@@ -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;
 }
index fee02da32f1e85675d20af2f7c7cb8df470f282a..bab3c86e16ad343fb2400dbfc9a0c94e4559dcb3 100644 (file)
@@ -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] == '@') {
index 9e828f2f0d629ec2880f950c4714e39aeb98efaf..ee3e0be8eb3dee0544260c1422ed00970986a8d0 100644 (file)
@@ -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__)
index ce3c8bde68fe7539fe43c83dc2cb68cdf16ef377..aa37c60466725ab02f300a65f240099f728f8868 100644 (file)
@@ -260,6 +260,15 @@ level context. It is equivalent to:
   talloc_named(NULL, 0, fmt, ...);
 
 
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+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);
 
index 22444b11168b632bbf4aaa23d0afd89e8071b2d7..a3a448ef40864cbe9e10136ac50e809551825c8e 100644 (file)
@@ -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);
index 8b05b98e0ea20bd4062514ddb58a28e240cf2326..ec103dbfa415de6139864560805a8375b59278c1 100644 (file)
@@ -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) {
index 11be8ffba78d5c32a14eed3064fbde9c774b6469..e0b54cacc3273dfd80bd3c4b6468d00803799b64 100644 (file)
@@ -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;
index 4204adcc07712cf6995a3ba5344178c806e8dc19..843d45607b8bb382d19478b26cbae365e88484f0 100644 (file)
@@ -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);
index 89ad2e24306e50093158197c58ea7226da3555db..3254330c2f774368b88b47ac2ff196fdcbb5efe7 100644 (file)
@@ -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);
index f8d0ba1c279a9ca06ce621120685dcaf0e11d117..8e057f214b9a74b43c684dad958d7f7094192f15 100644 (file)
@@ -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 */
index baa6c15e3169bbb03a77dc5ca2076c360edb0a40..ca535db1686933808a1bf93853ad23001b02338a 100644 (file)
@@ -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;
 
index 12fe50c2776d76c7c2f6661166da2377f5107f9b..eebae38ab790b2bf56fdad9c94ae0d4a97c9a1b0 100644 (file)
@@ -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;
index f29ed51a498dae66e9323aea5d75da4e4cd08165..a1a5244453080760a0d65a658230db0772a8842c 100644 (file)
@@ -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;
 
index 0e0032058f9509b09e0a28775209d506dd56a952..7308805da7d96bf52f2a223eafea300bfb091d02 100644 (file)
@@ -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);
index 7d0e3e84a8ff1d65e96462d2aa45b8372926e9e8..3f30d7123fdd06066d9f56baa9946dab810267c7 100644 (file)
@@ -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);
 
index 5064c1a061937ede27725194ada2ee0957f90db0..55acaba2b2cd915592c61e25afb72863a16761ff 100644 (file)
@@ -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;
index de93d6731fea808e361aac1099ff2e860bacb734..3df1f3be41cd4474aa0269b4c915f671a4e3ac7b 100644 (file)
@@ -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;