diff --git a/CHANGES b/CHANGES
index 9bb6cee8244fca772160a1d28fa11cfd4c6bb65c..45f337abb6b77b9448a3df7838e340b253c9a3cd 100644
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,7 @@ OpenLDAP 2.4.13 Release (2008/11/20)
 	Fixed slapacl crasher (ITS#5820)
 	Fixed slapd acl checks on ADD (ITS#4556,ITS#5723)
 	Fixed slapd acl application to newly created backends (ITS#5572)
+	Fixed slapd #if/#elif issues in thread includes (ITS#5824)
 	Added slapd keyword add_content_acl for add checks (ITS#4556,ITS#5723)
 	Fixed slapd concurrent access to connections (ITS#5814)
 	Fixed slapd config backend olcLogFile support (ITS#5765)
diff --git a/include/ldap_int_thread.h b/include/ldap_int_thread.h
index f1f72abf75aeeabc6bebee2efc5cd8f7214688f8..75899e51e8fa49e1fa576c8d0ce1e6d40a5c1ffd 100644
--- a/include/ldap_int_thread.h
+++ b/include/ldap_int_thread.h
@@ -80,7 +80,7 @@ LDAP_END_DECL
 
 #if defined( HAVE_MACH_CTHREADS_H )
 #	include <mach/cthreads.h>
-#elif defined( HAVE_CTHREAD_H
+#elif defined( HAVE_CTHREADS_H )
 #	include <cthreads.h>
 #endif
 
diff --git a/include/ldap_pvt_thread.h b/include/ldap_pvt_thread.h
index 1325e77226716024999e4f09125f2b0de811fdef..7dc34c217a1f2819bc837a320254635017ecf17d 100644
--- a/include/ldap_pvt_thread.h
+++ b/include/ldap_pvt_thread.h
@@ -59,12 +59,12 @@ ldap_pvt_thread_set_concurrency LDAP_P(( int ));
 
 #ifndef LDAP_PVT_THREAD_H_DONE
 #define	LDAP_PVT_THREAD_SET_STACK_SIZE
-#ifndef LDAP_PVT_THREAD_STACK_SIZE
+/* The size may be explicitly #defined to zero to disable it. */
+#if defined( LDAP_PVT_THREAD_STACK_SIZE ) && LDAP_PVT_THREAD_STACK_SIZE == 0
+#	undef LDAP_PVT_THREAD_SET_STACK_SIZE
+#elif !defined( LDAP_PVT_THREAD_STACK_SIZE )
 	/* LARGE stack. Will be twice as large on 64 bit machine. */
-#define LDAP_PVT_THREAD_STACK_SIZE	( 1 * 1024 * 1024 * sizeof(void *) )
-/* May be explicitly defined to zero to disable it */
-#elif LDAP_PVT_THREAD_STACK_SIZE == 0
-#undef LDAP_PVT_THREAD_SET_STACK_SIZE
+#	define LDAP_PVT_THREAD_STACK_SIZE ( 1 * 1024 * 1024 * sizeof(void *) )
 #endif
 #endif /* !LDAP_PVT_THREAD_H_DONE */