Index: src/xptmalloc.c
===================================================================
--- src/xptmalloc.c	(Revision 2377)
+++ src/xptmalloc.c	(Arbeitskopie)
@@ -235,7 +235,8 @@
  * See above for the *BSD situation.
  */
 
-#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
+#if defined(SBRK_OK) && \
+  !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
 #define REPLACE_MALLOC
 #endif
 
@@ -249,7 +250,9 @@
 {
     in_malloc = 0;
     print_block(0, 0);
+#ifdef REPLACE_MALLOC
     count_up(clib_alloc_stat, 0);
+#endif
 }
 
 /***************************************************************************/
Index: src/driver.h
===================================================================
--- src/driver.h	(Revision 2377)
+++ src/driver.h	(Arbeitskopie)
@@ -49,17 +49,26 @@
 #  define GC_SUPPORT 1
 #endif
 
+
 /* Do some of the selected packages require special treatment? */
 
-/* SQLite in the threadsafe mode needs a normal malloc() */
-#if defined(SBRK_OK) && defined(USE_SQLITE) && defined(SQLITE3_USES_PTHREADS)
-#  undef SBRK_OK
-#endif
+/* ptmalloc only works correctly with SBRK_OK right now. */
+#ifdef MALLOC_ptmalloc
+#  ifndef SBRK_OK
+#    define SBRK_OK
+#  endif
+#else // no ptmalloc
+/* SQLite in the threadsafe mode needs a normal malloc() if the allocator is
+ * not ptmalloc*/
+#  if defined(SBRK_OK) && defined(USE_SQLITE) && defined(SQLITE3_USES_PTHREADS)
+#      undef SBRK_OK
+#  endif
+/* PTHREADS need a normal malloc() if the allocator is not ptmalloc */
+#  if defined(SBRK_OK) && defined(USE_PTHREADS)
+#      undef SBRK_OK
+#  endif
+#endif // MALLOC_ptmalloc
 
-/* PTHREADS need a normal malloc() */
-#if defined(SBRK_OK) && defined(USE_PTHREADS)
-#  undef SBRK_OK
-#endif
 
 /* When we have allocation tracing, the allocator annotates every
  * allocation with the source filename and line where the allocation
