This adds the two functions talloc_stackframe() and talloc_tos().
* When a new talloc stackframe is allocated with talloc_stackframe(), then
* the TALLOC_CTX returned with talloc_tos() is reset to that new
* frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse
* happens: The previous talloc_tos() is restored.
*
* This API is designed to be robust in the sense that if someone forgets to
* TALLOC_FREE() a stackframe, then the next outer one correctly cleans up and
* resets the talloc_tos().
The original motivation for this patch was to get rid of the
sid_string_static & friends buffers. Explicitly passing talloc context
everywhere clutters code too much for my taste, so an implicit
talloc_tos() is introduced here. Many of these static buffers are
replaced by a single static pointer.
The intended use would thus be that low-level functions can rather
freely push stuff to talloc_tos, the upper layers clean up by freeing
the stackframe. The more of these stackframes are used and correctly
freed the more exact the memory cleanup happens.
This patch removes the main_loop_talloc_ctx, tmp_talloc_ctx and
lp_talloc_ctx (did I forget any?)
So, never do a
tmp_ctx = talloc_init("foo");
anymore, instead, use
tmp_ctx = talloc_stackframe()
:-)
Volker
LIB_WITHOUT_PROTO_OBJ = $(LIBREPLACE_OBJ) $(SOCKET_WRAPPER_OBJ) $(TALLOC_OBJ) \
lib/messages.o librpc/gen_ndr/ndr_messaging.o lib/messages_local.o \
- lib/messages_ctdbd.o lib/packet.o lib/ctdbd_conn.o
+ lib/messages_ctdbd.o lib/packet.o lib/ctdbd_conn.o lib/talloc_stack.o
LIB_WITH_PROTO_OBJ = $(VERSION_OBJ) lib/charcnv.o lib/debug.o lib/fault.o \
lib/interface.o lib/md4.o \
#include "dbwrap.h"
#include "packet.h"
#include "ctdbd_conn.h"
+#include "talloc_stack.h"
/*
* Type for wide character dirent structure.
--- /dev/null
+/*
+ Unix SMB/CIFS implementation.
+ Implement a stack of talloc contexts
+ Copyright (C) Volker Lendecke 2007
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ * Implement a stack of talloc frames.
+ *
+ * When a new talloc stackframe is allocated with talloc_stackframe(), then
+ * the TALLOC_CTX returned with talloc_tos() is reset to that new
+ * frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse
+ * happens: The previous talloc_tos() is restored.
+ *
+ * This API is designed to be robust in the sense that if someone forgets to
+ * TALLOC_FREE() a stackframe, then the next outer one correctly cleans up and
+ * resets the talloc_tos().
+ *
+ */
+
+#ifndef _TALLOC_STACK_H
+#define _TALLOC_STACK_H
+
+#include "lib/talloc/talloc.h"
+
+/*
+ * Create a new talloc stack frame.
+ *
+ * When free'd, it frees all stack frames that were created after this one and
+ * not explicitly freed.
+ */
+
+TALLOC_CTX *talloc_stackframe(void);
+
+/*
+ * Get us the current top of the talloc stack.
+ */
+
+TALLOC_CTX *talloc_tos(void);
+
+#endif
--- /dev/null
+/*
+ Unix SMB/CIFS implementation.
+ Implement a stack of talloc contexts
+ Copyright (C) Volker Lendecke 2007
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ * Implement a stack of talloc frames.
+ *
+ * When a new talloc stackframe is allocated with talloc_stackframe(), then
+ * the TALLOC_CTX returned with talloc_tos() is reset to that new
+ * frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse
+ * happens: The previous talloc_tos() is restored.
+ *
+ * This API is designed to be robust in the sense that if someone forgets to
+ * TALLOC_FREE() a stackframe, then the next outer one correctly cleans up and
+ * resets the talloc_tos().
+ *
+ * This robustness feature means that we can't rely on a linked list with
+ * talloc destructors because in a hierarchy of talloc destructors the parent
+ * destructor is called before its children destructors. The child destructor
+ * called after the parent would set the talloc_tos() to the wrong value.
+ */
+
+#include "includes.h"
+
+static int talloc_stacksize;
+static TALLOC_CTX **talloc_stack;
+
+static int talloc_pop(int *ptr)
+{
+ int tos = *ptr;
+ int i;
+
+ for (i=talloc_stacksize-1; i>=tos; i--) {
+ talloc_free(talloc_stack[i]);
+ }
+
+ talloc_stacksize = tos;
+ return 0;
+}
+
+/*
+ * Create a new talloc stack frame.
+ *
+ * When free'd, it frees all stack frames that were created after this one and
+ * not explicitly freed.
+ */
+
+TALLOC_CTX *talloc_stackframe(void)
+{
+ TALLOC_CTX **tmp, *top;
+ int *cleanup;
+
+ if (!(tmp = TALLOC_REALLOC_ARRAY(NULL, talloc_stack, TALLOC_CTX *,
+ talloc_stacksize + 1))) {
+ goto fail;
+ }
+
+ talloc_stack = tmp;
+
+ if (!(top = talloc_new(talloc_stack))) {
+ goto fail;
+ }
+
+ if (!(cleanup = talloc(top, int))) {
+ goto fail;
+ }
+
+ *cleanup = talloc_stacksize;
+ talloc_set_destructor(cleanup, talloc_pop);
+
+ talloc_stack[talloc_stacksize++] = top;
+
+ return top;
+
+ fail:
+ smb_panic("talloc_stackframe failed");
+ return NULL;
+}
+
+/*
+ * Get us the current top of the talloc stack.
+ */
+
+TALLOC_CTX *talloc_tos(void)
+{
+ if (talloc_stacksize == 0) {
+ DEBUG(0, ("no talloc stackframe around, leaking memory\n"));
+ talloc_stackframe();
+ }
+
+ return talloc_stack[talloc_stacksize-1];
+}
SMB4ACL_T *smb_create_smb4acl(void)
{
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
SMB_ACL4_INT_T *acl = (SMB_ACL4_INT_T *)TALLOC_ZERO_SIZE(mem_ctx, sizeof(SMB_ACL4_INT_T));
if (acl==NULL)
{
SMB4ACE_T *smb_add_ace4(SMB4ACL_T *acl, SMB_ACE4PROP_T *prop)
{
SMB_ACL4_INT_T *aclint = get_validated_aclint(acl);
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
SMB_ACE4_INT_T *ace;
ace = (SMB_ACE4_INT_T *)TALLOC_ZERO_SIZE(mem_ctx, sizeof(SMB_ACE4_INT_T));
size_t sd_size = 0;
SEC_ACE *nt_ace_list = NULL;
SEC_ACL *psa = NULL;
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
DEBUG(10, ("smb_get_nt_acl_nfs4 invoked for %s\n", fsp->fsp_name));
{
SMB4ACL_T *acl;
uint32 i;
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
DEBUG(10, ("smbacl4_win2nfs4 invoked\n"));
if (string_to_sid(&sid, name)) {
const char *user, *domain;
/* We have to find the type, look up the SID */
- lookup_sid(tmp_talloc_ctx(), &sid,
+ lookup_sid(talloc_tos(), &sid,
&domain, &user, &type);
}
*p = '\\';
}
- if (!lookup_name(tmp_talloc_ctx(), name, LOOKUP_NAME_ALL,
+ if (!lookup_name(talloc_tos(), name, LOOKUP_NAME_ALL,
&domain, &uname, &sid, &type)) {
DEBUG(10, ("Could not find AFS user %s\n", name));
SEC_ACL *psa = NULL;
int good_aces;
size_t sd_size;
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
struct afs_ace *afs_ace;
} else {
- if (!lookup_sid(tmp_talloc_ctx(), &ace->trustee,
+ if (!lookup_sid(talloc_tos(), &ace->trustee,
&dom_name, &name, &name_type)) {
DEBUG(1, ("AFSACL: Could not lookup SID %s on file %s\n",
sid_string_static(&ace->trustee), filename));
(name_type == SID_NAME_DOM_GRP) ||
(name_type == SID_NAME_ALIAS) ) {
char *tmp;
- tmp = talloc_asprintf(tmp_talloc_ctx(), "%s%s%s",
+ tmp = talloc_asprintf(talloc_tos(), "%s%s%s",
dom_name, lp_winbind_separator(),
name);
if (tmp == NULL) {
if (sidpts) {
/* Expect all users/groups in pts as SIDs */
name = talloc_strdup(
- tmp_talloc_ctx(),
+ talloc_tos(),
sid_string_static(&ace->trustee));
if (name == NULL) {
return False;
uint64_t ctl_flag=0;
TALLOC_CTX *mem_ctx;
- mem_ctx = main_loop_talloc_get();
+ mem_ctx = talloc_tos();
acl = (AIXJFS2_ACL_T *)TALLOC_SIZE(mem_ctx, len);
if (acl == NULL) {
errno = ENOMEM;
DEBUG(10, ("jfs2_process_smbacl invoked on %s\n", fsp->fsp_name));
/* no need to be freed which is alloced with mem_ctx */
- mem_ctx = main_loop_talloc_get();
+ mem_ctx = talloc_tos();
entryLen = sizeof(nfs4_ace_int_t);
if (entryLen & 0x03)
struct gpfs_acl *acl;
size_t len = 200;
int ret;
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
acl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, len);
if (acl == NULL) {
gpfs_aclLen_t gacl_len;
SMB4ACE_T *smbace;
struct gpfs_acl *gacl;
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
gacl_len = sizeof(struct gpfs_acl) +
(smb_get_naces(smbacl)-1)*sizeof(gpfs_ace_v4_t);
return 0;
}
/* allocate the field of ZFS aces */
- mem_ctx = main_loop_talloc_get();
+ mem_ctx = talloc_tos();
acebuf = (ace_t *) talloc_size(mem_ctx, sizeof(ace_t)*naces);
if(acebuf == NULL) {
errno = ENOMEM;
TALLOC_CTX *mem_ctx;
/* allocate the field of ZFS aces */
- mem_ctx = main_loop_talloc_get();
+ mem_ctx = talloc_tos();
acebuf = (ace_t *) talloc_size(mem_ctx, sizeof(ace_t)*naces);
if(acebuf == NULL) {
errno = ENOMEM;
while( True ) {
time_t t = time(NULL);
+ TALLOC_CTX *frame = talloc_stackframe();
/* Check for internal messages */
* (nmbd_packets.c)
*/
- if(listen_for_packets(run_election))
+ if(listen_for_packets(run_election)) {
+ TALLOC_FREE(frame);
return;
+ }
/*
* Handle termination inband.
NULL, MSG_SMB_CONF_UPDATED,
procid_self(), &blob);
- if(no_subnets)
+ if(no_subnets) {
+ TALLOC_FREE(frame);
return;
+ }
reload_after_sighup = 0;
}
/* check for new network interfaces */
- if(reload_interfaces(t))
+ if(reload_interfaces(t)) {
+ TALLOC_FREE(frame);
return;
+ }
/* free up temp memory */
- lp_TALLOC_FREE();
+ TALLOC_FREE(frame);
}
}
rescan_trusted_domains();
- /* Free up temporary memory */
-
- lp_TALLOC_FREE();
- main_loop_TALLOC_FREE();
-
/* Initialise fd lists for select() */
maxfd = MAX(listen_sock, listen_priv_sock);
}
for (;;) {
+ TALLOC_CTX *frame = talloc_stackframe();
int clients = process_loop(listen_public, listen_priv);
/* Don't bother figuring out the idle time if we won't be
* timing out anyway.
*/
if (idle_timeout_sec < 0) {
+ TALLOC_FREE(frame);
continue;
}
} else {
starttime = timeval_current();
}
+ TALLOC_FREE(frame);
}
}
struct timeval t;
struct timeval *tp;
struct timeval now;
-
- /* free up any talloc memory */
- lp_TALLOC_FREE();
- main_loop_TALLOC_FREE();
+ TALLOC_CTX *frame = talloc_stackframe();
run_events(winbind_event_context(), 0, NULL, NULL);
if (ret == 0) {
DEBUG(11,("nothing is ready yet, continue\n"));
+ TALLOC_FREE(frame);
continue;
}
if (ret == -1 && errno == EINTR) {
/* We got a signal - continue. */
+ TALLOC_FREE(frame);
continue;
}
if (ret == -1 && errno != EINTR) {
DEBUG(0,("select error occured\n"));
+ TALLOC_FREE(frame);
perror("select");
return False;
}
DEBUG(0, ("Could not write result\n"));
exit(1);
}
+ TALLOC_FREE(frame);
}
}
Globals.bRegistryShares = False;
}
-static TALLOC_CTX *lp_talloc;
-
-/******************************************************************* a
- Free up temporary memory - called from the main loop.
-********************************************************************/
-
-void lp_TALLOC_FREE(void)
-{
- if (!lp_talloc)
- return;
- TALLOC_FREE(lp_talloc);
- lp_talloc = NULL;
-}
-
-TALLOC_CTX *tmp_talloc_ctx(void)
-{
- if (lp_talloc == NULL) {
- lp_talloc = talloc_init("tmp_talloc_ctx");
- }
-
- if (lp_talloc == NULL) {
- smb_panic("Could not create temporary talloc context");
- }
-
- return lp_talloc;
-}
-
/*******************************************************************
Convenience routine to grab string parameters into temporary memory
and run standard_sub_basic on them. The buffers can be written to by
DEBUG(10, ("lp_string(%s)\n", s));
#endif
- if (!lp_talloc)
- lp_talloc = talloc_init("lp_talloc");
-
tmpstr = alloc_sub_basic(get_current_username(),
current_user_info.domain, s);
if (trim_char(tmpstr, '\"', '\"')) {
current_user_info.domain, s);
}
}
- ret = talloc_strdup(lp_talloc, tmpstr);
+ ret = talloc_strdup(talloc_tos(), tmpstr);
SAFE_FREE(tmpstr);
return (ret);
/* Return parametric option from a given service. Type is a part of option before ':' */
/* Parametric option has following syntax: 'Type: option = value' */
-/* the returned value is talloced in lp_talloc */
+/* the returned value is talloced on the talloc_tos() */
char *lp_parm_talloc_string(int snum, const char *type, const char *option, const char *def)
{
param_opt_struct *data = get_parametrics(snum, type, option);
const char *suffix_string;
- if (!lp_talloc)
- lp_talloc = talloc_init("lp_talloc");
-
- suffix_string = talloc_asprintf( lp_talloc, "%s,%s", str, Globals.szLdapSuffix );
+ suffix_string = talloc_asprintf(talloc_tos(), "%s,%s", str,
+ Globals.szLdapSuffix );
if ( !suffix_string ) {
DEBUG(0,("append_ldap_suffix: talloc_asprintf() failed!\n"));
return "";
struct file_lists *next;
int i;
- lp_TALLOC_FREE();
-
/* Free the file lists */
f = file_lists;
}
/* This returns a 33 byte guarenteed null terminated string. */
- ret = talloc_strndup(main_loop_talloc_get(), label, 32);
+ ret = talloc_strndup(talloc_tos(), label, 32);
if (!ret) {
return "";
}
for ( i=0; i<privileges->count; i++ ) {
privname = luid_to_privilege_name( &privileges->set[i].luid );
if ( privname ) {
- if ( !add_string_to_array( get_talloc_ctx(), privname, &privname_array, &num_priv ) )
+ if ( !add_string_to_array( talloc_tos(), privname, &privname_array, &num_priv ) )
return NT_STATUS_NO_MEMORY;
}
}
if ( num_priv ) {
- out->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
+ out->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
if (!out->rights) {
return NT_STATUS_NO_MEMORY;
}
in->pol = *hnd;
init_dom_sid2(&in->sid, sid);
- in->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
+ in->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
if (!in->rights) {
smb_panic("init_q_add_acct_rights: talloc fail\n");
return;
in->removeall = removeall;
in->count = count;
- in->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
+ in->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
if (!in->rights) {
smb_panic("init_q_remove_acct_rights: talloc fail\n");
return;
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_PARSE
-/****************************************************************************
- A temporary TALLOC context for things like unistrs, that is valid for
- the life of a complete RPC call.
-****************************************************************************/
-
-static TALLOC_CTX *current_rpc_talloc = NULL;
-
-static TALLOC_CTX *get_current_rpc_talloc(void)
-{
- return current_rpc_talloc;
-}
-
-void set_current_rpc_talloc( TALLOC_CTX *ctx)
-{
- current_rpc_talloc = ctx;
-}
-
-static TALLOC_CTX *main_loop_talloc = NULL;
-
-/*******************************************************************
-free up temporary memory - called from the main loop
-********************************************************************/
-
-void main_loop_TALLOC_FREE(void)
-{
- if (!main_loop_talloc)
- return;
- talloc_destroy(main_loop_talloc);
- main_loop_talloc = NULL;
-}
-
-/*******************************************************************
- Get a talloc context that is freed in the main loop...
-********************************************************************/
-
-TALLOC_CTX *main_loop_talloc_get(void)
-{
- if (!main_loop_talloc) {
- main_loop_talloc = talloc_init("main loop talloc (mainly parse_misc)");
- if (!main_loop_talloc)
- smb_panic("main_loop_talloc: malloc fail");
- }
-
- return main_loop_talloc;
-}
-
-/*******************************************************************
- Try and get a talloc context. Get the rpc one if possible, else
- get the main loop one. The main loop one is more dangerous as it
- goes away between packets, the rpc one will stay around for as long
- as a current RPC lasts.
-********************************************************************/
-
-TALLOC_CTX *get_talloc_ctx(void)
-{
- TALLOC_CTX *tc = get_current_rpc_talloc();
-
- if (tc)
- return tc;
- return main_loop_talloc_get();
-}
-
/*******************************************************************
Reads or writes a UTIME type.
********************************************************************/
len = strlen(buf) + 1;
if (len) {
- str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
+ str->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, len);
if (str->buffer == NULL)
smb_panic("init_unistr: malloc fail");
static void create_rpc_blob(RPC_DATA_BLOB *str, size_t len)
{
if (len) {
- str->buffer = (uint8 *)TALLOC_ZERO(get_talloc_ctx(), len);
+ str->buffer = (uint8 *)TALLOC_ZERO(talloc_tos(), len);
if (str->buffer == NULL)
smb_panic("create_rpc_blob: talloc fail");
str->buf_len = len;
if (buf != NULL) {
SMB_ASSERT(str->buf_max_len >= str->buf_len);
- str->buffer = (uint16 *)TALLOC_ZERO(get_talloc_ctx(),
+ str->buffer = (uint16 *)TALLOC_ZERO(talloc_tos(),
str->buf_max_len);
if (str->buffer == NULL)
smb_panic("init_regval_buffer: talloc fail");
reallocation of memory. */
if (str->buffer == NULL) {
if (str->uni_max_len) {
- str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, str->uni_max_len);
+ str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_max_len);
if ((str->buffer == NULL)) {
smb_panic("copy_unistr2: talloc fail");
return;
/* store the string */
if(str_len != 0) {
- str->buffer = (uint8 *)TALLOC_ZERO(get_talloc_ctx(),
+ str->buffer = (uint8 *)TALLOC_ZERO(talloc_tos(),
str->str_max_len);
if (str->buffer == NULL)
smb_panic("init_string2: malloc fail");
}
- str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
+ str->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, len);
if (str->buffer == NULL) {
smb_panic("init_unistr2: malloc fail");
return;
void init_unistr4(UNISTR4 *uni4, const char *buf, enum unistr2_term_codes flags)
{
- uni4->string = TALLOC_P( get_talloc_ctx(), UNISTR2 );
+ uni4->string = TALLOC_P( talloc_tos(), UNISTR2 );
if (!uni4->string) {
smb_panic("init_unistr4: talloc fail");
return;
/* allocate the space and copy the string buffer */
if (i) {
- to->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, i);
+ to->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, i);
if (to->buffer == NULL)
smb_panic("init_unistr2_from_unistr: malloc fail");
memcpy(to->buffer, from->buffer, i*sizeof(uint16));
if (UNMARSHALLING(ps)) {
if (array->count) {
- if ( !(array->strings = TALLOC_ZERO_ARRAY( get_talloc_ctx(), UNISTR4, array->count)) )
+ if ( !(array->strings = TALLOC_ZERO_ARRAY( talloc_tos(), UNISTR4, array->count)) )
return False;
} else {
array->strings = NULL;
/* allocate memory for the array of UNISTR4 objects */
if (array->count) {
- if ( !(array->strings = TALLOC_ZERO_ARRAY(get_talloc_ctx(), UNISTR4, count )) )
+ if ( !(array->strings = TALLOC_ZERO_ARRAY(talloc_tos(), UNISTR4, count )) )
return False;
} else {
array->strings = NULL;
str->uni_str_len = strlen(buf) + 1;
if (str->uni_str_len) {
- str->str.buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, str->uni_str_len);
+ str->str.buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_str_len);
if (str->str.buffer == NULL)
smb_panic("init_unistr3: malloc fail");
q_u->buffer_size = 0x000000a8;
if ( UNMARSHALLING(ps) ) {
- q_u->buffer = TALLOC_ARRAY(get_talloc_ctx(), uint8, q_u->buffer_size );
+ q_u->buffer = TALLOC_ARRAY(talloc_tos(), uint8, q_u->buffer_size );
if (!q_u->buffer) {
return False;
}
if ( UNMARSHALLING(ps) ) {
if (r_u->buffer_size) {
- r_u->buffer = TALLOC_ARRAY(get_talloc_ctx(), uint8, r_u->buffer_size );
+ r_u->buffer = TALLOC_ARRAY(talloc_tos(), uint8, r_u->buffer_size );
if (!r_u->buffer) {
return False;
}
{
DEBUG(5,("make_spoolss_q_open_printer_ex\n"));
- q_u->printername = TALLOC_P( get_talloc_ctx(), UNISTR2 );
+ q_u->printername = TALLOC_P( talloc_tos(), UNISTR2 );
if (!q_u->printername) {
return False;
}
q_u->user_switch = 1;
q_u->user_ctr.level = 1;
- q_u->user_ctr.user.user1 = TALLOC_P( get_talloc_ctx(), SPOOL_USER_1 );
+ q_u->user_ctr.user.user1 = TALLOC_P( talloc_tos(), SPOOL_USER_1 );
if (!q_u->user_ctr.user.user1) {
return False;
}
q_u->user_ctr.user.user1->minor = 0;
q_u->user_ctr.user.user1->processor = 0;
- q_u->user_ctr.user.user1->client_name = TALLOC_P( get_talloc_ctx(), UNISTR2 );
+ q_u->user_ctr.user.user1->client_name = TALLOC_P( talloc_tos(), UNISTR2 );
if (!q_u->user_ctr.user.user1->client_name) {
return False;
}
- q_u->user_ctr.user.user1->user_name = TALLOC_P( get_talloc_ctx(), UNISTR2 );
+ q_u->user_ctr.user.user1->user_name = TALLOC_P( talloc_tos(), UNISTR2 );
if (!q_u->user_ctr.user.user1->user_name) {
return False;
}
q_u->user_switch=1;
q_u->user_ctr.level = 1;
- q_u->user_ctr.user.user1 = TALLOC_P( get_talloc_ctx(), SPOOL_USER_1 );
+ q_u->user_ctr.user.user1 = TALLOC_P( talloc_tos(), SPOOL_USER_1 );
if (!q_u->user_ctr.user.user1) {
return False;
}
if ( UNMARSHALLING(ps)) {
if (fa->num_actions) {
- if ( !(fa->actions = TALLOC_ARRAY( get_talloc_ctx(), SC_ACTION, fa->num_actions )) ) {
+ if ( !(fa->actions = TALLOC_ARRAY( talloc_tos(), SC_ACTION, fa->num_actions )) ) {
DEBUG(0,("svcctl_io_service_fa: talloc() failure!\n"));
return False;
}
pipe_fns = find_pipe_fns_by_context(p->contexts, p->hdr_req.context_id);
if ( pipe_fns ) {
- set_current_rpc_talloc(p->mem_ctx);
+ TALLOC_CTX *frame = talloc_stackframe();
ret = api_rpcTNP(p, p->name, pipe_fns->cmds, pipe_fns->n_cmds);
- set_current_rpc_talloc(NULL);
+ TALLOC_FREE(frame);
}
else {
DEBUG(0,("api_pipe_request: No rpc function table associated with context [%d] on pipe [%s]\n",
DEBUG(4,("short name:%s\n", Printer->sharename));
*number = print_queue_snum(Printer->sharename);
if ((*number != -1) && (params != NULL)) {
- *params = get_share_params(tmp_talloc_ctx(),
+ *params = get_share_params(talloc_tos(),
Printer->sharename);
if (*params == NULL) {
return False;
/* don't use talloc_steal() here unless you do a deep steal of all
the SEC_DESC members */
- printer->secdesc = dup_sec_desc( get_talloc_ctx(),
+ printer->secdesc = dup_sec_desc( talloc_tos(),
ntprinter->info_2->secdesc_buf->sd );
}
/* don't use talloc_steal() here unless you do a deep steal of all
the SEC_DESC members */
- printer->secdesc = dup_sec_desc( get_talloc_ctx(),
+ printer->secdesc = dup_sec_desc( talloc_tos(),
ntprinter->info_2->secdesc_buf->sd );
}
static WERROR net_file_enum_3(pipes_struct *p, union srvsvc_NetFileCtr *ctr, uint32 *resume_hnd, uint32 *num_entries )
{
- TALLOC_CTX *ctx = get_talloc_ctx();
WERROR status;
/* TODO -- Windows enumerates
ctr->ctr3 = TALLOC_ZERO_P(p->mem_ctx, struct srvsvc_NetFileCtr3);
- status = net_enum_files( ctx, &ctr->ctr3->array, num_entries, resume_hnd );
+ status = net_enum_files(p->mem_ctx, &ctr->ctr3->array, num_entries, resume_hnd );
if ( !W_ERROR_IS_OK(status))
return status;
- status = net_enum_pipes( ctx, &ctr->ctr3->array, num_entries, resume_hnd );
+ status = net_enum_pipes(p->mem_ctx, &ctr->ctr3->array, num_entries, resume_hnd );
if ( !W_ERROR_IS_OK(status))
return status;
{
struct smb_request *req;
- if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) {
+ if (!(req = talloc(talloc_tos(), struct smb_request))) {
smb_panic("Could not allocate smb_request");
}
/* We finally got the lock, return success. */
- if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) {
+ if (!(req = talloc(talloc_tos(), struct smb_request))) {
blocking_lock_reply_error(blr, NT_STATUS_NO_MEMORY);
return True;
}
return False;
}
- num_sessions = list_sessions(tmp_talloc_ctx(), &session_list);
+ num_sessions = list_sessions(talloc_tos(), &session_list);
if (mdrcnt > 0) {
*rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
char **tmp;
- tmp = TALLOC_REALLOC_ARRAY(tmp_talloc_ctx(), cliprotos, char *,
+ tmp = TALLOC_REALLOC_ARRAY(talloc_tos(), cliprotos, char *,
num_cliprotos+1);
if (tmp == NULL) {
DEBUG(0, ("talloc failed\n"));
goto done;
}
- if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) {
+ if (!(req = talloc(talloc_tos(), struct smb_request))) {
change_notify_reply_packet(request_buf, NT_STATUS_NO_MEMORY);
goto done;
}
pdata = data + sd_len;
/* We have already checked that ea_len <= data_count here. */
- ea_list = read_nttrans_ea_list(tmp_talloc_ctx(), pdata,
+ ea_list = read_nttrans_ea_list(talloc_tos(), pdata,
ea_len);
if (!ea_list ) {
TALLOC_FREE(case_state);
return print_fsp_open(conn, fname, result);
}
- if (!parent_dirname_talloc(tmp_talloc_ctx(), fname, &parent_dir,
+ if (!parent_dirname_talloc(talloc_tos(), fname, &parent_dir,
&newname)) {
return NT_STATUS_NO_MEMORY;
}
return status;
}
- if (!parent_dirname_talloc(tmp_talloc_ctx(), name, &parent_dir,
+ if (!parent_dirname_talloc(talloc_tos(), name, &parent_dir,
&dirname)) {
return NT_STATUS_NO_MEMORY;
}
}
if (num_aces) {
- if((psa = make_sec_acl( main_loop_talloc_get(), NT4_ACL_REVISION, num_aces, nt_ace_list)) == NULL) {
+ if((psa = make_sec_acl( talloc_tos(), NT4_ACL_REVISION, num_aces, nt_ace_list)) == NULL) {
DEBUG(0,("get_nt_acl: Unable to malloc space for acl.\n"));
goto done;
}
}
} /* security_info & DACL_SECURITY_INFORMATION */
- psd = make_standard_sec_desc( main_loop_talloc_get(),
+ psd = make_standard_sec_desc( talloc_tos(),
(security_info & OWNER_SECURITY_INFORMATION) ? &owner_sid : NULL,
(security_info & GROUP_SECURITY_INFORMATION) ? &group_sid : NULL,
psa,
file_chain_reset();
reset_chain_p();
- if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) {
+ if (!(req = talloc(talloc_tos(), struct smb_request))) {
smb_panic("could not allocate smb_request");
}
init_smb_request(req, (uint8 *)inbuf);
DEBUG(3,("Chained message\n"));
show_msg(inbuf2);
- if (!(req2 = talloc(tmp_talloc_ctx(), struct smb_request))) {
+ if (!(req2 = talloc(talloc_tos(), struct smb_request))) {
smb_panic("could not allocate smb_request");
}
init_smb_request(req2, (uint8 *)inbuf2);
int num_echos;
char *inbuf;
size_t inbuf_len;
+ TALLOC_CTX *frame = talloc_stackframe();
errno = 0;
- /* free up temporary memory */
- lp_TALLOC_FREE();
- main_loop_TALLOC_FREE();
-
/* Did someone ask for immediate checks on things like blocking locks ? */
if (select_timeout == 0) {
if(!timeout_processing(&select_timeout,
change_to_root_user();
check_log_size();
}
+ TALLOC_FREE(frame);
}
}
fd_set r_fds, w_fds;
int num;
- /* Free up temporary memory from the main smbd. */
- lp_TALLOC_FREE();
-
/* Ensure we respond to PING and DEBUG messages from the main smbd. */
message_dispatch(smbd_messaging_context());
return;
}
- ea_list = read_ea_list(tmp_talloc_ctx(), pdata + 4,
+ ea_list = read_ea_list(talloc_tos(), pdata + 4,
total_data - 4);
if (!ea_list) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
return;
}
- ea_list = read_ea_list(tmp_talloc_ctx(), pdata + 4,
+ ea_list = read_ea_list(talloc_tos(), pdata + 4,
total_data - 4);
if (!ea_list) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ALL,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ALL,
&dom, &name, &sid, &type)) {
d_printf("Could not lookup name %s\n", argv[0]);
return -1;
return -1;
}
- if (!lookup_sid(tmp_talloc_ctx(), &sid,
+ if (!lookup_sid(talloc_tos(), &sid,
&dom, &name, &type)) {
d_printf("Could not lookup name %s\n", argv[0]);
return -1;
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
map.gid = grp->gr_gid;
grpname = grp->gr_name;
- if (lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
+ if (lookup_name(talloc_tos(), grpname, LOOKUP_NAME_ISOLATED,
&dom, &name, NULL, NULL)) {
const char *tmp = talloc_asprintf(
- tmp_talloc_ctx(), "Unix Group %s", grp->gr_name);
+ talloc_tos(), "Unix Group %s", grp->gr_name);
DEBUG(5, ("%s exists as %s\\%s, retrying as \"%s\"\n",
grpname, dom, name, tmp));
grpname = tmp;
}
- if (lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
+ if (lookup_name(talloc_tos(), grpname, LOOKUP_NAME_ISOLATED,
NULL, NULL, NULL, NULL)) {
DEBUG(3, ("\"%s\" exists, can't map it\n", grp->gr_name));
return NT_STATUS_GROUP_EXISTS;
sid_compose(&map.sid, get_global_sam_sid(), rid);
map.sid_name_use = SID_NAME_DOM_GRP;
- fstrcpy(map.comment, talloc_asprintf(tmp_talloc_ctx(), "Unix Group %s",
+ fstrcpy(map.comment, talloc_asprintf(talloc_tos(), "Unix Group %s",
grp->gr_name));
status = pdb_add_group_mapping_entry(&map);
map.gid = grp->gr_gid;
grpname = grp->gr_name;
- if (!lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), grpname, LOOKUP_NAME_ISOLATED,
NULL, NULL, NULL, NULL)) {
DEBUG(3, ("\"%s\" does not exist, can't unmap it\n", grp->gr_name));
return NT_STATUS_NO_SUCH_GROUP;
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find %s.\n", argv[0]);
return -1;
fstrcpy( groupname, "BUILTIN\\" );
fstrcat( groupname, argv[0] );
- if ( !lookup_name(tmp_talloc_ctx(), groupname, LOOKUP_NAME_ALL, NULL,
+ if ( !lookup_name(talloc_tos(), groupname, LOOKUP_NAME_ALL, NULL,
NULL, &sid, &type)) {
d_fprintf(stderr, "%s is not a BUILTIN group\n", argv[0]);
return -1;
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&groupdomain, &groupname, &group, &grouptype)) {
d_fprintf(stderr, "Could not find group %s\n", argv[0]);
return -1;
/* check to see if the member to be added is a name or a SID */
- if (!lookup_name(tmp_talloc_ctx(), argv[1], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_ISOLATED,
&memberdomain, &membername, &member, &membertype))
{
/* try it as a SID */
return -1;
}
- if ( !lookup_sid(tmp_talloc_ctx(), &member, &memberdomain,
+ if ( !lookup_sid(talloc_tos(), &member, &memberdomain,
&membername, &membertype) )
{
d_fprintf(stderr, "Could not resolve SID %s\n", argv[1]);
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&groupdomain, &groupname, &group, &grouptype)) {
d_fprintf(stderr, "Could not find group %s\n", argv[0]);
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[1], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_ISOLATED,
&memberdomain, &membername, &member, NULL)) {
if (!string_to_sid(&member, argv[1])) {
d_fprintf(stderr, "Could not find member %s\n",
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&groupdomain, &groupname, &group, &grouptype)) {
d_fprintf(stderr, "Could not find group %s\n", argv[0]);
return -1;
(unsigned int)num_members);
for (i=0; i<num_members; i++) {
const char *dom, *name;
- if (lookup_sid(tmp_talloc_ctx(), &members[i],
+ if (lookup_sid(talloc_tos(), &members[i],
&dom, &name, NULL)) {
d_printf(" %s\\%s\n", dom, name);
} else {
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;