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

Volker Lendecke vlendec at samba.org
Fri Nov 14 18:56:51 GMT 2008


The branch, v3-2-test has been updated
       via  b0031a6e86565857e602f8011e57e2114835581a (commit)
       via  26b1fda4020b7f6629865ae1c62e9b464222e1a2 (commit)
       via  70e5b876b6b422c44ea588dbe319b6ce86a035d7 (commit)
       via  27b0b8f99c6d5b43d9b9079aa74789e27d0a8d84 (commit)
      from  3d2570150201e357f31e3d651bc05b7234c84796 (commit)

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


- Log -----------------------------------------------------------------
commit b0031a6e86565857e602f8011e57e2114835581a
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Nov 14 13:42:54 2008 +0100

    Make memcache_add_talloc NULL out the source pointer
    
    This is an orthogonality measure to make clear this pointer now belongs to the
    cache.

commit 26b1fda4020b7f6629865ae1c62e9b464222e1a2
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Nov 13 23:50:19 2008 +0100

    Actually finish memcache_add_talloc
    
    This fixes a memleak found by Martin Zielinski <mz at seh.de>. Thanks for
    looking closely!
    
    Volker

commit 70e5b876b6b422c44ea588dbe319b6ce86a035d7
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Jun 14 10:59:11 2008 +0200

    Use the correct cups-devel test for HAVE_IPRINT also
    (cherry picked from commit a42d7e1146e7469062ead2c8f22f549a48154e03)

commit 27b0b8f99c6d5b43d9b9079aa74789e27d0a8d84
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Jun 14 10:31:11 2008 +0200

    Correctly check for presence of cups-devel
    
    On SuSE at least cups-config belongs to cups-libs which does not contain the
    headers which are in cups-devel.
    (cherry picked from commit 2408d2493f7c6e0beee58febd547516bbeb0929d)

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

Summary of changes:
 source/auth/token_util.c      |    6 ++++--
 source/configure.in           |   19 +++++++++++++++++--
 source/lib/memcache.c         |   31 +++++++++++++++++++++++++++++--
 source/lib/util_pw.c          |    2 +-
 source/passdb/pdb_interface.c |   14 +++++++-------
 source/torture/torture.c      |   33 ++++++++++++++++++++++++++++++++-
 6 files changed, 90 insertions(+), 15 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/auth/token_util.c b/source/auth/token_util.c
index cd67c2a..bdf6124 100644
--- a/source/auth/token_util.c
+++ b/source/auth/token_util.c
@@ -77,7 +77,7 @@ bool nt_token_check_domain_rid( NT_USER_TOKEN *token, uint32 rid )
 
 NT_USER_TOKEN *get_root_nt_token( void )
 {
-	struct nt_user_token *token = NULL;
+	struct nt_user_token *token, *for_cache;
 	DOM_SID u_sid, g_sid;
 	struct passwd *pw;
 	void *cache_data;
@@ -107,9 +107,11 @@ NT_USER_TOKEN *get_root_nt_token( void )
 
 	token->privileges = se_disk_operators;
 
+	for_cache = token;
+
 	memcache_add_talloc(
 		NULL, SINGLETON_CACHE_TALLOC,
-		data_blob_string_const("root_nt_token"), token);
+		data_blob_string_const("root_nt_token"), &for_cache);
 
 	return token;
 }
diff --git a/source/configure.in b/source/configure.in
index 5a3abd0..64a4681 100644
--- a/source/configure.in
+++ b/source/configure.in
@@ -756,10 +756,25 @@ if test x$enable_cups != xno; then
 	AC_PATH_PROG(CUPS_CONFIG, cups-config)
 
         if test "x$CUPS_CONFIG" != x; then
-                AC_DEFINE(HAVE_CUPS,1,[Whether we have CUPS])
+
+		ac_save_CFLAGS=$CFLAGS
+		ac_save_LDFLAGS=$LDFLAGS
+		ac_save_PRINT_LIBS=$PRINT_LIBS
 		CFLAGS="$CFLAGS `$CUPS_CONFIG --cflags`"
 		LDFLAGS="$LDFLAGS `$CUPS_CONFIG --ldflags`"
 		PRINT_LIBS="$PRINT_LIBS `$CUPS_CONFIG --libs`"
+		AC_CHECK_HEADERS(cups/cups.h cups/language.h)
+		if test x"$ac_cv_header_cups_cups_h" = xyes -a \
+		        x"$ac_cv_header_cups_language_h" = xyes; then
+			AC_DEFINE(HAVE_CUPS,1,[Whether we have CUPS])
+			samba_cv_HAVE_CUPS=yes
+		else
+			AC_MSG_WARN([cups-config around but cups-devel not installed])
+			CFLAGS=$ac_save_CFLAGS
+			LDFLAGS=$ac_save_LDFLAGS
+			PRINT_LIBS=$ac_save_PRINT_LIBS
+		fi
+
 	elif test x"$enable_cups" = x"yes"; then
 		AC_MSG_ERROR(Cups support required but cups-config not located.  Make sure cups-devel related files are installed.)
         fi
@@ -769,7 +784,7 @@ AC_ARG_ENABLE(iprint,
 [AS_HELP_STRING([--enable-iprint], [Turn on iPrint support (default=yes if cups is yes)])])
 
 if test x$enable_iprint != xno; then
-	if test "x$CUPS_CONFIG" != x; then
+	if test x"$samba_cv_HAVE_CUPS" = xyes; then
                 AC_DEFINE(HAVE_IPRINT,1,[Whether we have iPrint])
 	elif test x"$enable_iprint" = x"yes"; then
 		AC_MSG_ERROR(iPrint support required but cups not enabled.  Make sure cups-devel related files are installed and that cups is enabled.)
diff --git a/source/lib/memcache.c b/source/lib/memcache.c
index e1426bc..4edd9c6 100644
--- a/source/lib/memcache.c
+++ b/source/lib/memcache.c
@@ -214,6 +214,16 @@ static void memcache_delete_element(struct memcache *cache,
 	}
 	DLIST_REMOVE(cache->mru, e);
 
+	if (memcache_is_talloc(e->n)) {
+		DATA_BLOB cache_key, cache_value;
+		void *ptr;
+
+		memcache_element_parse(e, &cache_key, &cache_value);
+		SMB_ASSERT(cache_value.length == sizeof(ptr));
+		memcpy(&ptr, cache_value.data, sizeof(ptr));
+		TALLOC_FREE(ptr);
+	}
+
 	cache->size -= memcache_element_size(e->keylength, e->valuelength);
 
 	SAFE_FREE(e);
@@ -276,6 +286,12 @@ void memcache_add(struct memcache *cache, enum memcache_number n,
 		memcache_element_parse(e, &cache_key, &cache_value);
 
 		if (value.length <= cache_value.length) {
+			if (memcache_is_talloc(e->n)) {
+				void *ptr;
+				SMB_ASSERT(cache_value.length == sizeof(ptr));
+				memcpy(&ptr, cache_value.data, sizeof(ptr));
+				TALLOC_FREE(ptr);
+			}
 			/*
 			 * We can reuse the existing record
 			 */
@@ -332,9 +348,20 @@ void memcache_add(struct memcache *cache, enum memcache_number n,
 }
 
 void memcache_add_talloc(struct memcache *cache, enum memcache_number n,
-			 DATA_BLOB key, void *ptr)
+			 DATA_BLOB key, void *pptr)
 {
-	memcache_add(cache, n, key, data_blob_const(&ptr, sizeof(ptr)));
+	void **ptr = (void **)pptr;
+	void *p;
+
+	if (cache == NULL) {
+		cache = global_cache;
+	}
+	if (cache == NULL) {
+		return;
+	}
+
+	p = talloc_move(cache, ptr);
+	memcache_add(cache, n, key, data_blob_const(&p, sizeof(p)));
 }
 
 void memcache_flush(struct memcache *cache, enum memcache_number n)
diff --git a/source/lib/util_pw.c b/source/lib/util_pw.c
index c0a44c7..b07fab1 100644
--- a/source/lib/util_pw.c
+++ b/source/lib/util_pw.c
@@ -63,7 +63,7 @@ struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
 	}
 
 	memcache_add_talloc(NULL, GETPWNAM_CACHE, data_blob_string_const(name),
-			    for_cache);
+			    &for_cache);
 
 	return tcopy_passwd(mem_ctx, pw);
 }
diff --git a/source/passdb/pdb_interface.c b/source/passdb/pdb_interface.c
index dd9fd1b..b83d618 100644
--- a/source/passdb/pdb_interface.c
+++ b/source/passdb/pdb_interface.c
@@ -207,28 +207,28 @@ static struct pdb_methods *pdb_get_methods(void)
 bool pdb_getsampwnam(struct samu *sam_acct, const char *username) 
 {
 	struct pdb_methods *pdb = pdb_get_methods();
-	struct samu *cache_copy;
+	struct samu *for_cache;
 	const struct dom_sid *user_sid;
 
 	if (!NT_STATUS_IS_OK(pdb->getsampwnam(pdb, sam_acct, username))) {
 		return False;
 	}
 
-	cache_copy = samu_new(NULL);
-	if (cache_copy == NULL) {
+	for_cache = samu_new(NULL);
+	if (for_cache == NULL) {
 		return False;
 	}
 
-	if (!pdb_copy_sam_account(cache_copy, sam_acct)) {
-		TALLOC_FREE(cache_copy);
+	if (!pdb_copy_sam_account(for_cache, sam_acct)) {
+		TALLOC_FREE(for_cache);
 		return False;
 	}
 
-	user_sid = pdb_get_user_sid(cache_copy);
+	user_sid = pdb_get_user_sid(for_cache);
 
 	memcache_add_talloc(NULL, PDB_GETPWSID_CACHE,
 			    data_blob_const(user_sid, sizeof(*user_sid)),
-			    cache_copy);
+			    &for_cache);
 
 	return True;
 }
diff --git a/source/torture/torture.c b/source/torture/torture.c
index e909f8c..0bacc07 100644
--- a/source/torture/torture.c
+++ b/source/torture/torture.c
@@ -5188,6 +5188,11 @@ static bool run_local_memcache(int dummy)
 	DATA_BLOB d1, d2, d3;
 	DATA_BLOB v1, v2, v3;
 
+	TALLOC_CTX *mem_ctx;
+	char *str1, *str2;
+	size_t size1, size2;
+	bool ret = false;
+
 	cache = memcache_init(NULL, 100);
 
 	if (cache == NULL) {
@@ -5239,7 +5244,33 @@ static bool run_local_memcache(int dummy)
 	}
 
 	TALLOC_FREE(cache);
-	return true;
+
+	cache = memcache_init(NULL, 0);
+
+	mem_ctx = talloc_init("foo");
+
+	str1 = talloc_strdup(mem_ctx, "string1");
+	str2 = talloc_strdup(mem_ctx, "string2");
+
+	memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
+			    data_blob_string_const("torture"), &str1);
+	size1 = talloc_total_size(cache);
+
+	memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
+			    data_blob_string_const("torture"), &str2);
+	size2 = talloc_total_size(cache);
+
+	printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
+
+	if (size2 > size1) {
+		printf("memcache leaks memory!\n");
+		goto fail;
+	}
+
+	ret = true;
+ fail:
+	TALLOC_FREE(cache);
+	return ret;
 }
 
 static double create_procs(bool (*fn)(int), bool *result)


-- 
Samba Shared Repository


More information about the samba-cvs mailing list