--- samba-3.0.24/source/nsswitch/winbindd_cred_cache.c	2007-02-05 03:59:14.000000000 +0900
+++ samba-3.0.24.osstech/source/nsswitch/winbindd_cred_cache.c	2007-03-01 14:51:19.430579378 +0900
@@ -89,6 +89,7 @@ NTSTATUS remove_ccache_by_ccname(const c
 #ifdef DEBUG_PASSWORD
 				DEBUG(10,("munlocked memory: %p\n", entry->pass));
 #endif
+				SAFE_FREE(entry->pass);
 			}
 #endif /* HAVE_MUNLOCK */
 			TALLOC_FREE(entry);
@@ -249,8 +250,19 @@ NTSTATUS add_ccache_to_list(const char *
 #ifdef HAVE_MLOCK
 		size_t len = strlen(pass)+1;
 		
-		new_entry->pass = TALLOC_ZERO(mem_ctx, len);
-		NT_STATUS_HAVE_NO_MEMORY(new_entry->pass);
+#if defined(LINUX)
+		/* aligning the memory on on x86_64 and compiling 
+		   with gcc 4.1 using -O2 causes a segv in the 
+		   next memset()  --jerry */
+		new_entry->pass = SMB_MALLOC_ARRAY(unsigned char, len);
+#else
+		new_entry->pass = SMB_MEMALIGN_ARRAY(unsigned char,
+						     getpagesize(), len);
+#endif
+		if (!new_entry->pass) {
+			return NT_STATUS_NO_MEMORY;
+		}
+		memset(new_entry->pass, 0x0, len);
 		
 #ifdef DEBUG_PASSWORD
 		DEBUG(10,("mlocking memory: %p\n", new_entry->pass));
@@ -258,6 +270,7 @@ NTSTATUS add_ccache_to_list(const char *
 		if ((mlock(new_entry->pass, len)) == -1) {
 			DEBUG(0,("failed to mlock memory: %s (%d)\n", 
 				strerror(errno), errno));
+			SAFE_FREE(new_entry->pass);
 			return map_nt_error_from_unix(errno);
 		} 
 		
@@ -275,6 +288,17 @@ NTSTATUS add_ccache_to_list(const char *
 	new_entry->renew_until = renew_until;
 	new_entry->ccname = talloc_strdup(mem_ctx, ccname);
 	if (new_entry->ccname == NULL) {
+		if (new_entry->pass != NULL) {
+#ifdef HAVE_MUNLOCK
+			size_t len = strlen(new_entry->pass)+1;
+			memset(new_entry->pass, 0, len);
+			if ((munlock(new_entry->pass, len)) == -1) {
+				DEBUG(0,("failed to munlock memory: %s (%d)\n", 
+					strerror(errno), errno));
+			}
+#endif /* HAVE_MUNLOCK */
+			SAFE_FREE(new_entry->pass);
+		}
 		return NT_STATUS_NO_MEMORY;
 	}
 	new_entry->uid = uid;
