r18584: found one of the fd leaks. The registry backend was using a
authorAndrew Tridgell <tridge@samba.org>
Sat, 16 Sep 2006 16:59:37 +0000 (16:59 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:18:52 +0000 (14:18 -0500)
talloc(NULL, xxx) to allocate the registry context. That had two
consequences

1) it was a massive memory leak, as all winreg operations leaked their
   entire context (including an open ldb database) every time

2) event_context_find() never found the exsting event context, so we
   used a new event context each time, which called epoll_create()
   each time, which caused a fd to be allocated
(This used to be commit 1c0a3de39828b43149d8981fc7f10e7c8b59a392)

source4/gtk/tools/gregedit.c
source4/lib/registry/reg_samba.c
source4/lib/registry/tools/regdiff.c
source4/lib/registry/tools/regpatch.c
source4/lib/registry/tools/regshell.c
source4/lib/registry/tools/regtree.c
source4/rpc_server/winreg/rpc_winreg.c

index e0717187d97cb1d13af2bf8f86ed8ef99c06a102..cf03eebec845da0e40f816eebc1e764bbb559b70 100644 (file)
@@ -385,7 +385,7 @@ static void on_open_gconf_activate(GtkMenuItem *menuitem, gpointer user_data)
 
 static void on_open_local_activate(GtkMenuItem *menuitem, gpointer user_data)
 {
-       WERROR error = reg_open_local(&registry, NULL, NULL);
+       WERROR error = reg_open_local(NULL, &registry, NULL, NULL);
        if(!W_ERROR_IS_OK(error)) {
                gtk_show_werror(mainwin, "Error while opening local registry", error);
                return;
@@ -953,7 +953,7 @@ static GtkWidget* create_savefilewin (void)
 
 static int gregedit_load_defaults(void)
 {
-       WERROR error = reg_open_local(&registry, NULL, NULL);
+       WERROR error = reg_open_local(NULL, &registry, NULL, NULL);
        if(!W_ERROR_IS_OK(error)) {
                gtk_show_werror(mainwin, "Error while loading local registry", error);
                return -1;
index 4a88d96042f33b0f95b5f343f3c054b6a9310bba..3553c4cb6d19149749f2fd4d7df57c296b90e14c 100644 (file)
@@ -68,9 +68,12 @@ static WERROR reg_samba_get_predef (struct registry_context *ctx, uint32_t hkey,
        return error;
 }
 
-_PUBLIC_ WERROR reg_open_local (struct registry_context **ctx, struct auth_session_info *session_info, struct cli_credentials *credentials)
+_PUBLIC_ WERROR reg_open_local (TALLOC_CTX *mem_ctx, 
+                               struct registry_context **ctx, 
+                               struct auth_session_info *session_info, 
+                               struct cli_credentials *credentials)
 {
-       *ctx = talloc(NULL, struct registry_context);
+       *ctx = talloc(mem_ctx, struct registry_context);
        (*ctx)->credentials = talloc_reference(*ctx, credentials);
        (*ctx)->session_info = talloc_reference(*ctx, session_info);
        (*ctx)->get_predefined_key = reg_samba_get_predef;
index dbbe555ad69ae60d82c5315cf3fa7a72b3ebb014..b8bf654a6b7d3c5efda9c3a41e968f50cce835c6 100644 (file)
@@ -54,8 +54,8 @@ int main(int argc, char **argv)
                error = WERR_OK;
                switch(opt)     {
                case 'L':
-                       if (!h1 && !from_null) error = reg_open_local(&h1, NULL, cmdline_credentials);
-                       else if (!h2) error = reg_open_local(&h2, NULL, cmdline_credentials);
+                       if (!h1 && !from_null) error = reg_open_local(NULL, &h1, NULL, cmdline_credentials);
+                       else if (!h2) error = reg_open_local(NULL, &h2, NULL, cmdline_credentials);
                        break;
                case 'R':
                        if (!h1 && !from_null) 
index 7ed246566cb4418201d2747724079fbba4028f22..42cdac860beab5bffef380d85ca5f978ff020c83 100644 (file)
@@ -52,7 +52,7 @@ int main(int argc, char **argv)
        if (remote) {
                error = reg_open_remote (&h, NULL, cmdline_credentials, remote, NULL);
        } else {
-               error = reg_open_local (&h, NULL, cmdline_credentials);
+               error = reg_open_local (NULL, &h, NULL, cmdline_credentials);
        }
 
        if (W_ERROR_IS_OK(error)) {
index 0bc1cfe3242b0d5f852546f259d8ae78eae76ee0..8436a3f505e463ac5aa7c32ec09da78c0f3b793f 100644 (file)
@@ -434,7 +434,7 @@ static char **reg_completion(const char *text, int start, int end)
        } else if (backend) {
                error = reg_open_hive(NULL, backend, poptGetArg(pc), NULL, cmdline_credentials, &curkey);
        } else {
-               error = reg_open_local(&h, NULL, cmdline_credentials);
+               error = reg_open_local(NULL, &h, NULL, cmdline_credentials);
        }
 
        if(!W_ERROR_IS_OK(error)) {
index 31f5a89a1b64c16c0d86b6f6ce3b45de16c40132..6b3c20eae3c02dba9f57720582937baa9c62e888 100644 (file)
@@ -122,7 +122,7 @@ int main(int argc, char **argv)
                        return 1;
                }
        } else {
-               error = reg_open_local (&h, NULL, cmdline_credentials);
+               error = reg_open_local (NULL, &h, NULL, cmdline_credentials);
 
                if(!W_ERROR_IS_OK(error)) {
                        fprintf(stderr, "Unable to open local registry:%s \n", win_errstr(error));
index adcbb749dac1a4691dfee8f24f0078454b1158a9..e32f620e5b65ec1c4efa0baa470460fd31b59acb 100644 (file)
@@ -32,7 +32,10 @@ enum handle_types { HTYPE_REGVAL, HTYPE_REGKEY };
 static NTSTATUS dcerpc_winreg_bind(struct dcesrv_call_state *dce_call, const struct dcesrv_interface *iface)
 {
        struct registry_context *ctx;
-       reg_open_local(&ctx, dce_call->conn->auth_state.session_info, NULL);
+       WERROR err;
+
+       err = reg_open_local(dce_call->context,
+                            &ctx, dce_call->conn->auth_state.session_info, NULL);
 
        dce_call->context->private = ctx;