[SCM] Samba Shared Repository - branch v3-2-test updated - release-3-2-0pre2-528-g16b5800

Michael Adam obnox at samba.org
Fri Mar 28 15:36:18 GMT 2008


The branch, v3-2-test has been updated
       via  16b5800d4e3a8b88bac67b2550d14e0aaaa302a9 (commit)
       via  971f6749ed23523f6eafe5136f6d4c920c20aec4 (commit)
      from  3250068eb980bd0489f814f702401cdc9c925a8d (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 16b5800d4e3a8b88bac67b2550d14e0aaaa302a9
Author: Michael Adam <obnox at samba.org>
Date:   Fri Mar 28 15:49:13 2008 +0100

    Add a talloc context parameter to current_timestring() to fix memleaks.
    
    current_timestring used to return a string talloced to talloc_tos().
    When called by DEBUG from a TALLOC_FREE, this produced messages
    "no talloc stackframe around, leaking memory". For example when
    used from net conf.
    
    This also adds a temporary talloc context to alloc_sub_basic().
    For this purpose, the exit strategy is slightly altered: a common
    exit point is used for success and failure.
    
    Michael

commit 971f6749ed23523f6eafe5136f6d4c920c20aec4
Author: Michael Adam <obnox at samba.org>
Date:   Fri Mar 28 15:39:52 2008 +0100

    srv_winreg: add a debug message to _winreg_CreateKey().
    
    Michael

-----------------------------------------------------------------------

Summary of changes:
 source/lib/debug.c                |   10 ++++++----
 source/lib/substitute.c           |   24 +++++++++++++++---------
 source/lib/time.c                 |    4 ++--
 source/libsmb/trusts_util.c       |    2 +-
 source/rpc_server/srv_winreg_nt.c |    3 +++
 source/rpcclient/cmd_spoolss.c    |   12 ++++++++----
 source/smbd/change_trust_pw.c     |    2 +-
 source/web/swat.c                 |    6 +++++-
 8 files changed, 41 insertions(+), 22 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/lib/debug.c b/source/lib/debug.c
index c4a0d1b..a76a8db 100644
--- a/source/lib/debug.c
+++ b/source/lib/debug.c
@@ -1029,12 +1029,14 @@ bool dbghdr(int level, int cls, const char *file, const char *func, int line)
 		/* Print it all out at once to prevent split syslog output. */
 		if( lp_debug_prefix_timestamp() ) {
 		    (void)Debug1( "[%s, %2d%s] ",
-			current_timestring(lp_debug_hires_timestamp()), level,
-			header_str);
+			current_timestring(debug_ctx(),
+					   lp_debug_hires_timestamp()),
+			level, header_str);
 		} else {
 		    (void)Debug1( "[%s, %2d%s] %s:%s(%d)\n",
-			current_timestring(lp_debug_hires_timestamp()), level,
-			header_str, file, func, line );
+			current_timestring(debug_ctx(),
+					   lp_debug_hires_timestamp()),
+			level, header_str, file, func, line );
 		}
 	}
 
diff --git a/source/lib/substitute.c b/source/lib/substitute.c
index 6ecc3fc..62dfdb5 100644
--- a/source/lib/substitute.c
+++ b/source/lib/substitute.c
@@ -548,6 +548,7 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
 	fstring pidstr, vnnstr;
 	char addr[INET6_ADDRSTRLEN];
 	const char *local_machine_name = get_local_machine_name();
+	TALLOC_CTX *tmp_ctx = NULL;
 
 	/* workaround to prevent a crash while looking at bug #687 */
 	
@@ -561,12 +562,14 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
 		DEBUG(0, ("alloc_sub_basic: Out of memory!\n"));
 		return NULL;
 	}
-	
+
+	tmp_ctx = talloc_stackframe();
+
 	for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
 
 		r = NULL;
 		b = a_string;
-		
+
 		switch (*(p+1)) {
 		case 'U' : 
 			r = strdup_lower(smb_name);
@@ -581,7 +584,7 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
 			if (r == NULL) {
 				goto error;
 			}
-			pass = Get_Pwnam_alloc(talloc_tos(), r);
+			pass = Get_Pwnam_alloc(tmp_ctx, r);
 			if (pass != NULL) {
 				a_string = realloc_string_sub(
 					a_string, "%G",
@@ -631,7 +634,7 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
 			a_string = realloc_string_sub(a_string, "%R", remote_proto);
 			break;
 		case 'T' :
-			a_string = realloc_string_sub(a_string, "%T", current_timestring(False));
+			a_string = realloc_string_sub(a_string, "%T", current_timestring(tmp_ctx, False));
 			break;
 		case 'a' :
 			a_string = realloc_string_sub(a_string, "%a",
@@ -669,17 +672,20 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
 
 		p++;
 		SAFE_FREE(r);
-		
-		if ( !a_string ) {
-			return NULL;
+
+		if (a_string == NULL) {
+			goto done;
 		}
 	}
 
-	return a_string;
+	goto done;
 
 error:
 	SAFE_FREE(a_string);
-	return NULL;
+
+done:
+	TALLOC_FREE(tmp_ctx);
+	return a_string;
 }
 
 /****************************************************************************
diff --git a/source/lib/time.c b/source/lib/time.c
index f98e031..e5fd929 100644
--- a/source/lib/time.c
+++ b/source/lib/time.c
@@ -687,7 +687,7 @@ int set_server_zone_offset(time_t t)
  Return the date and time as a string
 ****************************************************************************/
 
-char *current_timestring(bool hires)
+char *current_timestring(TALLOC_CTX *ctx, bool hires)
 {
 	fstring TimeBuf;
 	struct timeval tp;
@@ -739,7 +739,7 @@ char *current_timestring(bool hires)
 		}
 #endif
 	}
-	return talloc_strdup(talloc_tos(), TimeBuf);
+	return talloc_strdup(ctx, TimeBuf);
 }
 
 
diff --git a/source/libsmb/trusts_util.c b/source/libsmb/trusts_util.c
index c079fb1..8c2f69c 100644
--- a/source/libsmb/trusts_util.c
+++ b/source/libsmb/trusts_util.c
@@ -123,7 +123,7 @@ NTSTATUS trust_pw_change_and_store_it(struct rpc_pipe_client *cli, TALLOC_CTX *m
 	
 	if (NT_STATUS_IS_OK(nt_status)) {
 		DEBUG(3,("%s : trust_pw_change_and_store_it: Changed password.\n", 
-			 current_timestring(False)));
+			 current_timestring(debug_ctx(), False)));
 		/*
 		 * Return the result of trying to write the new password
 		 * back into the trust account file.
diff --git a/source/rpc_server/srv_winreg_nt.c b/source/rpc_server/srv_winreg_nt.c
index bf28ba6..7b74871 100644
--- a/source/rpc_server/srv_winreg_nt.c
+++ b/source/rpc_server/srv_winreg_nt.c
@@ -740,6 +740,9 @@ WERROR _winreg_CreateKey( pipes_struct *p, struct winreg_CreateKey *r)
 	if ( !parent )
 		return WERR_BADFID;
 
+	DEBUG(10, ("_winreg_CreateKey called with parent key '%s' and "
+		   "subkey name '%s'\n", parent->key->name, r->in.name.name));
+
 	result = reg_createkey(NULL, parent, r->in.name.name, r->in.access_mask,
 			       &new_key, r->out.action_taken);
 	if (!W_ERROR_IS_OK(result)) {
diff --git a/source/rpcclient/cmd_spoolss.c b/source/rpcclient/cmd_spoolss.c
index 5e0f694..7530ab1 100644
--- a/source/rpcclient/cmd_spoolss.c
+++ b/source/rpcclient/cmd_spoolss.c
@@ -1966,13 +1966,15 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
 	PRINTER_INFO_CTR ctr;
 	PRINTER_INFO_0 info;
 	REGISTRY_VALUE value;
+	TALLOC_CTX *tmp_ctx = talloc_stackframe();
 
 	/* parse the command arguements */
 	if (argc < 5) {
 		printf ("Usage: %s <printer> <string|binary|dword|multistring>"
 			" <value> <data>\n",
 			argv[0]);
-		return WERR_INVALID_PARAM;
+		result = WERR_INVALID_PARAM;
+		goto done;
 	}
 
 	slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->cli->desthost);
@@ -2000,7 +2002,8 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
 
 	if (value.type == REG_NONE) {
 		printf("Unknown data type: %s\n", argv[2]);
-		return WERR_INVALID_PARAM;
+		result =  WERR_INVALID_PARAM;
+		goto done;
 	}
 
 	/* get a printer handle */
@@ -2019,7 +2022,7 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
         if (!W_ERROR_IS_OK(result))
                 goto done;
 		
-	printf("%s\n", current_timestring(True));
+	printf("%s\n", current_timestring(tmp_ctx, True));
 	printf("\tchange_id (before set)\t:[0x%x]\n", info.change_id);
 
 	/* Set the printer data */
@@ -2105,11 +2108,12 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
         if (!W_ERROR_IS_OK(result))
                 goto done;
 		
-	printf("%s\n", current_timestring(True));
+	printf("%s\n", current_timestring(tmp_ctx, True));
 	printf("\tchange_id (after set)\t:[0x%x]\n", info.change_id);
 
 done:
 	/* cleanup */
+	TALLOC_FREE(tmp_ctx);
 	if (opened_hnd)
 		rpccli_spoolss_close_printer(cli, mem_ctx, &pol);
 
diff --git a/source/smbd/change_trust_pw.c b/source/smbd/change_trust_pw.c
index fc58e97..4773eef 100644
--- a/source/smbd/change_trust_pw.c
+++ b/source/smbd/change_trust_pw.c
@@ -90,7 +90,7 @@ NTSTATUS change_trust_account_password( const char *domain, const char *remote_m
 failed:
 	if (!NT_STATUS_IS_OK(nt_status)) {
 		DEBUG(0,("%s : change_trust_account_password: Failed to change password for domain %s.\n", 
-			current_timestring(False), domain));
+			current_timestring(debug_ctx(), False), domain));
 	}
 	else
 		DEBUG(5,("change_trust_account_password: sucess!\n"));
diff --git a/source/web/swat.c b/source/web/swat.c
index bb418db..6d8f4ca 100644
--- a/source/web/swat.c
+++ b/source/web/swat.c
@@ -438,11 +438,15 @@ static bool load_config(bool save_def)
 ****************************************************************************/
 static void write_config(FILE *f, bool show_defaults)
 {
+	TALLOC_CTX *ctx = talloc_stackframe();
+
 	fprintf(f, "# Samba config file created using SWAT\n");
 	fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
-	fprintf(f, "# Date: %s\n\n", current_timestring(False));
+	fprintf(f, "# Date: %s\n\n", current_timestring(ctx, False));
 	
 	lp_dump(f, show_defaults, iNumNonAutoPrintServices);
+
+	TALLOC_FREE(ctx);
 }
 
 /****************************************************************************


-- 
Samba Shared Repository


More information about the samba-cvs mailing list