Index: pkg-tls.c
===================================================================
--- pkg-tls.c   (Revision 149)
+++ pkg-tls.c   (Arbeitskopie)
@@ -189,6 +189,46 @@
     gnutls_dh_set_prime_bits( *session, DH_BITS);
 } /* initialize_tls_session() */
 
+/*-------------------------------------------------------------------------*/
+static void *
+tls_xalloc (size_t size)
+
+/* Wrapper function so that (gnu)tls will use our special allocator.
+ * Must use this construct since direct using is impossible due to
+ * the defines in xalloc.h.
+ */
+{
+    return xalloc(size);
+} /* tls_xalloc() */
+
+/*-------------------------------------------------------------------------*/
+static void *
+tls_rexalloc (void *old, size_t size)
+
+/* Wrapper function so that (gnu)tls will use our special allocator.
+ * It also takes care of the special behaviour of gnutls (realloc
+ * with NULL-pointer instead of using malloc.
+ */
+{
+  if (old == NULL)
+    return xalloc(size);
+  return rexalloc(old, size);
+} /* tls_rexalloc() */
+
+/*-------------------------------------------------------------------------*/
+static void
+tls_xfree (void *p)
+
+/* Wrapper function so that (gnu)tls will use our special allocator.
+ * It also takes care of the special behaviour of gnutls (freeing
+ *  NULL-pointers
+ */
+{
+  if (p == NULL)
+    return;
+  return xfree(p);
+} /* tls_free() */
+
 #endif /* SSL Package */ 
 
 /*-------------------------------------------------------------------------*/
@@ -341,6 +381,15 @@
     gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
 #endif
 
+   /* Use a special allocator since its impossible to do a sbrk_trace with
+    * the default one.
+    */
+    gnutls_global_set_mem_functions(tls_xalloc,
+                                    tls_xalloc,
+                                    NULL,
+                                    tls_rexalloc,
+                                    tls_xfree);
+
     gnutls_global_init();
 
     gnutls_certificate_allocate_credentials(&x509_cred);
