On non-linux platforms, mlock()'d memory must be aligned.
See also: http://lists.samba.org/archive/samba-technical/2007-February/051863.html

diff -urp samba-3.0.24/source/configure.in samba-3.0.24.osstech/source/configure.in
--- samba-3.0.24/source/configure.in	2007-02-05 03:59:28.000000000 +0900
+++ samba-3.0.24.osstech/source/configure.in	2007-02-26 16:49:26.643041650 +0900
@@ -1277,6 +1277,7 @@ AC_CHECK_FUNCS(syslog vsyslog timegm)
 AC_CHECK_FUNCS(setlocale nl_langinfo)
 AC_CHECK_FUNCS(nanosleep)
 AC_CHECK_FUNCS(mlock munlock mlockall munlockall)
+AC_CHECK_FUNCS(memalign posix_memalign)
 AC_CHECK_HEADERS(sys/mman.h)
 # setbuffer, shmget, shm_open are needed for smbtorture
 AC_CHECK_FUNCS(setbuffer shmget shm_open)
diff -urp samba-3.0.24/source/include/smb_macros.h samba-3.0.24.osstech/source/include/smb_macros.h
--- samba-3.0.24/source/include/smb_macros.h	2006-04-20 11:29:39.000000000 +0900
+++ samba-3.0.24.osstech/source/include/smb_macros.h	2007-02-26 16:49:26.687045048 +0900
@@ -275,6 +275,7 @@ copy an IP address from one buffer to an
 *****************************************************************************/
 
 #define SMB_MALLOC_ARRAY(type,count) (type *)malloc_array(sizeof(type),(count))
+#define SMB_MEMALIGN_ARRAY(type,align,count) (type *)memalign_array(sizeof(type),align,(count))
 #define SMB_REALLOC(p,s) Realloc((p),(s),True)	/* Always frees p on error or s == 0 */
 #define SMB_REALLOC_KEEP_OLD_ON_ERROR(p,s) Realloc((p),(s),False) /* Never frees p on error or s == 0 */
 #define SMB_REALLOC_ARRAY(p,type,count) (type *)realloc_array((p),sizeof(type),(count),True) /* Always frees p on error or s == 0 */
diff -urp samba-3.0.24/source/lib/system.c samba-3.0.24.osstech/source/lib/system.c
--- samba-3.0.24/source/lib/system.c	2006-04-20 11:29:23.000000000 +0900
+++ samba-3.0.24.osstech/source/lib/system.c	2007-02-26 16:49:26.747049681 +0900
@@ -42,6 +42,26 @@
 */
 
 
+/*******************************************************************
+ A wrapper for memalign
+********************************************************************/
+
+void* sys_memalign( size_t align, size_t size )
+{
+#if defined(HAVE_MEMALIGN)
+	return memalign( align, size );
+#elif defined(HAVE_POSIX_MEMALIGN)
+	char *p = NULL;
+	int ret = posix_memalign( &p, align, size );
+	if ( ret == 0 )
+		return p;
+		
+	return NULL;
+#else
+	DEBUG(0,("memalign functionalaity not available on this platform!\n"));
+	return NULL;
+#endif
+}
 
 /*******************************************************************
  A wrapper for usleep in case we don't have one.
diff -urp samba-3.0.24/source/lib/util.c samba-3.0.24.osstech/source/lib/util.c
--- samba-3.0.24/source/lib/util.c	2007-02-05 03:59:17.000000000 +0900
+++ samba-3.0.24.osstech/source/lib/util.c	2007-02-26 16:49:26.755050299 +0900
@@ -915,6 +915,17 @@ void *malloc_(size_t size)
 }
 
 /****************************************************************************
+ Internal malloc wrapper. Externally visible.
+****************************************************************************/
+
+void *memalign_(size_t align, size_t size)
+{
+#undef memalign
+	return memalign(align, size);
+#define memalign(align, s) __ERROR_DONT_USE_MEMALIGN_DIRECTLY
+}
+
+/****************************************************************************
  Internal calloc wrapper. Not externally visible.
 ****************************************************************************/
 
@@ -956,6 +967,23 @@ void *malloc_array(size_t el_size, unsig
 }
 
 /****************************************************************************
+ Type-safe memalign
+****************************************************************************/
+
+void *memalign_array(size_t el_size, size_t align, unsigned int count)
+{
+	if (count >= MAX_ALLOC_SIZE/el_size) {
+		return NULL;
+	}
+
+#if defined(PARANOID_MALLOC_CHECKER)
+	return memalign_(align, el_size*count);
+#else
+	return sys_memalign(align, el_size*count);
+#endif
+}
+
+/****************************************************************************
  Type-safe calloc.
 ****************************************************************************/
 
diff -urp samba-3.0.24/source/nsswitch/winbindd_cred_cache.c samba-3.0.24.osstech/source/nsswitch/winbindd_cred_cache.c
--- 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;
