Make use of talloc_pool in the main codepaths. Remove the sub-contexts.
authorJeremy Allison <jra@samba.org>
Thu, 10 Jan 2008 01:11:04 +0000 (17:11 -0800)
committerJeremy Allison <jra@samba.org>
Thu, 10 Jan 2008 01:11:04 +0000 (17:11 -0800)
Jeremy.

source/smbd/nttrans.c
source/smbd/open.c
source/smbd/process.c
source/smbd/service.c
source/smbd/trans2.c
source/smbd/vfs.c

index ae64c06215687d9982d3e018941dee9456d32ae3..e8df732ea23f3f59e30a03cb257f902b59dde181 100644 (file)
@@ -1604,7 +1604,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
        SEC_DESC *psd = NULL;
        size_t sd_size;
        uint32 security_info_wanted;
-       TALLOC_CTX *frame;
        files_struct *fsp = NULL;
        NTSTATUS status;
        DATA_BLOB blob;
@@ -1631,8 +1630,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
                return;
        }
 
-       frame = talloc_stackframe();
-
        /*
         * Get the permissions to return.
         */
@@ -1651,7 +1648,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
        }
 
        if (!NT_STATUS_IS_OK(status)) {
-               TALLOC_FREE(frame);
                reply_nterror(req, status);
                return;
        }
@@ -1665,7 +1661,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
        if (max_data_count < sd_size) {
                send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
                                params, 4, *ppdata, 0);
-               TALLOC_FREE(frame);
                return;
        }
 
@@ -1675,7 +1670,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
 
        data = nttrans_realloc(ppdata, sd_size);
        if(data == NULL) {
-               TALLOC_FREE(frame);
                reply_doserror(req, ERRDOS, ERRnomem);
                return;
        }
@@ -1684,7 +1678,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
                                   &blob.data, &blob.length);
 
        if (!NT_STATUS_IS_OK(status)) {
-               TALLOC_FREE(frame);
                reply_nterror(req, status);
                return;
        }
@@ -1694,7 +1687,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
 
        send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
 
-       TALLOC_FREE(frame);
        return;
 }
 
index 6aef99ff0e05bd0686b1b0d46347bf13298fa6cb..037ab633e3bfd52473d4f4ee2f5b73a2ee27d04e 100644 (file)
@@ -125,7 +125,7 @@ static NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
        char *saved_dir = NULL;
        SMB_STRUCT_STAT sbuf;
        SMB_STRUCT_STAT parent_st;
-       TALLOC_CTX *ctx = talloc_stackframe();
+       TALLOC_CTX *ctx = talloc_tos();
        NTSTATUS status = NT_STATUS_OK;
        int ret;
 
@@ -135,7 +135,6 @@ static NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
                DEBUG(0,("change_dir_owner_to_parent: failed to stat parent "
                         "directory %s. Error was %s\n",
                         inherit_from_dir, strerror(errno) ));
-               TALLOC_FREE(ctx);
                return status;
        }
 
@@ -152,7 +151,6 @@ static NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
                DEBUG(0,("change_dir_owner_to_parent: failed to get "
                         "current working directory. Error was %s\n",
                         strerror(errno)));
-               TALLOC_FREE(ctx);
                return status;
        }
 
@@ -202,7 +200,6 @@ static NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
 
  out:
 
-       TALLOC_FREE(ctx);
        vfs_ChDir(conn,saved_dir);
        return status;
 }
@@ -2707,7 +2704,6 @@ NTSTATUS create_file(connection_struct *conn,
                     int *pinfo,
                     SMB_STRUCT_STAT *psbuf)
 {
-       TALLOC_CTX *frame = talloc_stackframe();
        struct case_semantics_state *case_state = NULL;
        SMB_STRUCT_STAT sbuf;
        int info = FILE_WAS_OPENED;
@@ -2918,7 +2914,6 @@ NTSTATUS create_file(connection_struct *conn,
        if (psbuf != NULL) {
                *psbuf = sbuf;
        }
-       TALLOC_FREE(frame);
        return NT_STATUS_OK;
 
  fail:
@@ -2928,6 +2923,5 @@ NTSTATUS create_file(connection_struct *conn,
                close_file(fsp, ERROR_CLOSE);
                fsp = NULL;
        }
-       TALLOC_FREE(frame);
        return status;
 }
index fe32d57ff7ccada3cddfc30e4249df99bab99d9d..2d3cf7fbd8dd713334d3a0d877654307c2843c0f 100644 (file)
@@ -2071,7 +2071,7 @@ void smbd_process(void)
                char *inbuf;
                size_t inbuf_len;
                bool encrypted = false;
-               TALLOC_CTX *frame = talloc_stackframe();
+               TALLOC_CTX *frame = talloc_stackframe_pool(8192);
 
                errno = 0;
 
index 65fc8181446aecd2b54559fca492008249fac0c3..2588a66b8b923a861061a7856f6d15964a16de12 100644 (file)
@@ -357,7 +357,6 @@ void load_registry_shares(void)
 int find_service(fstring service)
 {
        int iService;
-       TALLOC_CTX *frame = talloc_stackframe();
 
        all_string_sub(service,"\\","/",0);
 
@@ -463,8 +462,6 @@ int find_service(fstring service)
        if (iService < 0)
                DEBUG(3,("find_service() failed to find service %s\n", service));
 
-       TALLOC_FREE(frame);
-
        return (iService);
 }
 
@@ -1150,20 +1147,17 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
 #if SOFTLINK_OPTIMISATION
        /* resolve any soft links early if possible */
        if (vfs_ChDir(conn,conn->connectpath) == 0) {
-               TALLOC_CTX *ctx = talloc_stackframe();
+               TALLOC_CTX *ctx = talloc_tos();
                char *s = vfs_GetWd(ctx,s);
                if (!s) {
                        *status = map_nt_error_from_unix(errno);
-                       TALLOC_FREE(ctx);
                        goto err_root_exit;
                }
                if (!set_conn_connectpath(conn,s)) {
                        *status = NT_STATUS_NO_MEMORY;
-                       TALLOC_FREE(ctx);
                        goto err_root_exit;
                }
                vfs_ChDir(conn,conn->connectpath);
-               TALLOC_FREE(ctx);
        }
 #endif
 
index 485513c734395ef1d09df0da86a3c16c4f02b040..ce0b239c4ec9f172284324b2d7e118079d8ae72a 100644 (file)
@@ -297,9 +297,8 @@ static unsigned int estimate_ea_size(connection_struct *conn, files_struct *fsp,
        if (!lp_ea_support(SNUM(conn))) {
                return 0;
        }
-       mem_ctx = talloc_init("estimate_ea_size");
+       mem_ctx = talloc_tos();
        (void)get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
-       talloc_destroy(mem_ctx);
        return total_ea_len;
 }
 
@@ -310,7 +309,7 @@ static unsigned int estimate_ea_size(connection_struct *conn, files_struct *fsp,
 static void canonicalize_ea_name(connection_struct *conn, files_struct *fsp, const char *fname, fstring unix_ea_name)
 {
        size_t total_ea_len;
-       TALLOC_CTX *mem_ctx = talloc_init("canonicalize_ea_name");
+       TALLOC_CTX *mem_ctx = talloc_tos();
        struct ea_list *ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
 
        for (; ea_list; ea_list = ea_list->next) {
@@ -321,7 +320,6 @@ static void canonicalize_ea_name(connection_struct *conn, files_struct *fsp, con
                        break;
                }
        }
-       talloc_destroy(mem_ctx);
 }
 
 /****************************************************************************
@@ -1955,9 +1953,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        out_of_space = True;
                        finished = False;
                } else {
-                       TALLOC_CTX *sub_ctx = talloc_stackframe();
-
-                       finished = !get_lanman2_dir_entry(sub_ctx,
+                       finished = !get_lanman2_dir_entry(ctx,
                                        conn,
                                        req->flags2,
                                        mask,dirtype,info_level,
@@ -1966,8 +1962,6 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                        space_remaining, &out_of_space,
                                        &got_exact_match,
                                        &last_entry_off, ea_list);
-
-                       TALLOC_FREE(sub_ctx);
                }
 
                if (finished && out_of_space)
@@ -2303,9 +2297,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        out_of_space = True;
                        finished = False;
                } else {
-                       TALLOC_CTX *sub_ctx = talloc_stackframe();
-
-                       finished = !get_lanman2_dir_entry(sub_ctx,
+                       finished = !get_lanman2_dir_entry(ctx,
                                                conn,
                                                req->flags2,
                                                mask,dirtype,info_level,
@@ -2314,8 +2306,6 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                                space_remaining, &out_of_space,
                                                &got_exact_match,
                                                &last_entry_off, ea_list);
-
-                       TALLOC_FREE(sub_ctx);
                }
 
                if (finished && out_of_space)
@@ -4759,17 +4749,12 @@ static NTSTATUS smb_info_set_ea(connection_struct *conn,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       ctx = talloc_init("SMB_INFO_SET_EA");
-       if (!ctx) {
-               return NT_STATUS_NO_MEMORY;
-       }
+       ctx = talloc_tos();
        ea_list = read_ea_list(ctx, pdata + 4, total_data - 4);
        if (!ea_list) {
-               talloc_destroy(ctx);
                return NT_STATUS_INVALID_PARAMETER;
        }
        status = set_ea(conn, fsp, fname, ea_list);
-       talloc_destroy(ctx);
 
        return status;
 }
index 9a5e0aff60ccb9a78640483f6fe238e0c4399b0e..bb4e77ed31f335794d04100f5116369188fcdb0a 100644 (file)
@@ -869,14 +869,13 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                                return map_nt_error_from_unix(errno);
                        case ENOENT:
                        {
-                               TALLOC_CTX *tmp_ctx = talloc_stackframe();
+                               TALLOC_CTX *ctx = talloc_tos();
                                char *tmp_fname = NULL;
                                char *last_component = NULL;
                                /* Last component didn't exist. Remove it and try and canonicalise the directory. */
 
-                               tmp_fname = talloc_strdup(tmp_ctx, fname);
+                               tmp_fname = talloc_strdup(ctx, fname);
                                if (!tmp_fname) {
-                                       TALLOC_FREE(tmp_ctx);
                                        return NT_STATUS_NO_MEMORY;
                                }
                                p = strrchr_m(tmp_fname, '/');
@@ -885,10 +884,9 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                                        last_component = p;
                                } else {
                                        last_component = tmp_fname;
-                                       tmp_fname = talloc_strdup(tmp_ctx,
+                                       tmp_fname = talloc_strdup(ctx,
                                                        ".");
                                        if (!tmp_fname) {
-                                               TALLOC_FREE(tmp_ctx);
                                                return NT_STATUS_NO_MEMORY;
                                        }
                                }
@@ -900,15 +898,13 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
 #endif
                                if (!resolved_name) {
                                        DEBUG(3,("reduce_name: couldn't get realpath for %s\n", fname));
-                                       TALLOC_FREE(tmp_ctx);
                                        return map_nt_error_from_unix(errno);
                                }
-                               tmp_fname = talloc_asprintf(tmp_ctx,
+                               tmp_fname = talloc_asprintf(ctx,
                                                "%s/%s",
                                                resolved_name,
                                                last_component);
                                if (!tmp_fname) {
-                                       TALLOC_FREE(tmp_ctx);
                                        return NT_STATUS_NO_MEMORY;
                                }
 #ifdef REALPATH_TAKES_NULL
@@ -922,7 +918,6 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                                safe_strcpy(resolved_name_buf, tmp_fname, PATH_MAX);
                                resolved_name = resolved_name_buf;
 #endif
-                               TALLOC_FREE(tmp_ctx);
                                break;
                        }
                        default: