1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

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 commit is contained in:
Andrew Tridgell 2005-01-06 02:32:43 +00:00 committed by Gerald (Jerry) Carter
parent 2ec3a137d7
commit e6c81d7c9f
21 changed files with 47 additions and 37 deletions

View 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;

View 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;

View 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';

View 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;

View 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;
}

View 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] == '@') {

View 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__)

View 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);

View 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);

View 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) {

View 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;

View 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);

View 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);

View 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 */

View 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;

View 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;

View 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;

View 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);

View 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);

View 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;

View 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;