patch to pool debugging to display the pool_creation and it's children
when you destroy them
BTW.. should the global pool be tagged as 'global'?

..Ian
the reason I'm posting is i'm not sure if there is a better way to open up the stderr log to print the stuff out.


Index: include/apr_pools.h
===================================================================
RCS file: /home/cvs/apr/include/apr_pools.h,v
retrieving revision 1.66
diff -u -r1.66 apr_pools.h
--- include/apr_pools.h 1 Jan 2002 23:49:23 -0000       1.66
+++ include/apr_pools.h 11 Jan 2002 20:07:28 -0000
@@ -92,8 +92,8 @@
  * NB These should ALL normally be commented out unless you REALLY
  * need them!!
  */
-/*
 #define APR_POOL_DEBUG
+/*
 */

#define APR_POOL_STRINGIZE(x) APR_POOL__STRINGIZE(x)
@@ -158,11 +158,23 @@
* (this flag only makes sense in combination with POOL_FNEW_ALLOCATOR)
*
*/
+#if defined(APR_POOL_DEBUG)
+#define apr_pool_create_ex( newpool, parent, abort_fn, flag) \
+ apr_pool_create_ex_dbg( newpool, parent, abort_fn, flag,__FILE__,__LINE__)
+
+APR_DECLARE(apr_status_t) apr_pool_create_ex_dbg(apr_pool_t **newpool,
+ apr_pool_t *parent,
+ apr_abortfunc_t abort_fn,
+ apr_uint32_t flags,
+ const char *file,
+ int line);
+#
+#else
APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
apr_pool_t *parent,
apr_abortfunc_t abort_fn,
apr_uint32_t flags);
-
+#endif
/**
* Create a new pool.
* @param newpool The pool we have just created.
Index: memory/unix/apr_pools.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
retrieving revision 1.127
diff -u -r1.127 apr_pools.c
--- memory/unix/apr_pools.c 10 Jan 2002 18:52:49 -0000 1.127
+++ memory/unix/apr_pools.c 11 Jan 2002 20:07:28 -0000
@@ -91,6 +91,12 @@


 #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)

+/*
+ * This option prints out the pool creation info
+ * (and info about its children)
+ * when the pool is destroyed.
+ */
+#define APR_POOL_DEBUG_VERBOSE

 /*
  * Structures
@@ -161,6 +167,8 @@

 #else /* !defined(APR_POOL_DEBUG) */
     debug_node_t         *nodes;
+    const char           *file;
+    int                   line;
 #if APR_HAS_THREADS
     apr_thread_mutex_t *mutex;
 #endif
@@ -887,6 +895,9 @@
     return mem;
 }

+/*
+ * (debug)
+ */
APR_DECLARE(void *) apr_pcalloc(apr_pool_t *pool, apr_size_t size)
{
void *mem;
@@ -934,9 +945,32 @@
free(node);
}
}
-
+/*
+ * destroy (debug)
+ */
APR_DECLARE(void) apr_pool_destroy(apr_pool_t *pool)
{
+#if defined APR_POOL_DEBUG_VERBOSE
+ apr_file_t *stderr_log=NULL;
+ apr_pool_t *child;
+
+ apr_file_open_stderr(&stderr_log,pool); /* XXX not sure about this one */
+ if (stderr_log) {
+ apr_file_printf(stderr_log,
+ "DEBUG: destroy pool tagged %s created %s:%d\n",
+ pool->tag, pool->file, pool->line);
+ child= pool->child;
+ while (child) {
+ apr_file_printf(stderr_log,
+ "DEBUG:\tpool child tagged %s created %s:%d\n",
+ child->tag, child->file, child->line);
+ child=child->sibling;
+ }
+ apr_file_close(stderr_log);
+ }
+#endif
+
+


     apr_pool_clear(pool);

     /* Remove the pool from the parents child list */
@@ -961,10 +995,16 @@
     free(pool);
 }

-APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
+/*
+ * create (debug)
+ * there is a macro which adds the file/line #
+ */
+APR_DECLARE(apr_status_t) apr_pool_create_ex_dbg(apr_pool_t **newpool,
                                              apr_pool_t *parent,
                                              apr_abortfunc_t abort_fn,
-                                             apr_uint32_t flags)
+                                             apr_uint32_t flags,
+                                             const char *file,
+                                             int line)
 {
     apr_pool_t *pool;

@@ -1027,6 +1067,9 @@
         pool->sibling = NULL;
         pool->ref = NULL;
     }
+
+    pool->file = file;
+    pool->line = line;

     *newpool = pool;

Index: include/apr_pools.h
===================================================================
RCS file: /home/cvs/apr/include/apr_pools.h,v
retrieving revision 1.66
diff -u -r1.66 apr_pools.h
--- include/apr_pools.h 1 Jan 2002 23:49:23 -0000       1.66
+++ include/apr_pools.h 11 Jan 2002 20:07:28 -0000
@@ -92,8 +92,8 @@
  * NB These should ALL normally be commented out unless you REALLY
  * need them!!
  */
-/* 
 #define APR_POOL_DEBUG
+/* 
 */
 
 #define APR_POOL_STRINGIZE(x) APR_POOL__STRINGIZE(x)
@@ -158,11 +158,23 @@
  *          (this flag only makes sense in combination with 
POOL_FNEW_ALLOCATOR)
  *
  */
+#if defined(APR_POOL_DEBUG)
+#define apr_pool_create_ex( newpool, parent, abort_fn, flag)  \
+    apr_pool_create_ex_dbg( newpool, parent, abort_fn, flag,__FILE__,__LINE__) 
 
+
+APR_DECLARE(apr_status_t) apr_pool_create_ex_dbg(apr_pool_t **newpool,
+                                             apr_pool_t *parent,
+                                             apr_abortfunc_t abort_fn,
+                                             apr_uint32_t flags,
+                                             const char *file,
+                                             int line);
+#
+#else
 APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
                                              apr_pool_t *parent,
                                              apr_abortfunc_t abort_fn,
                                              apr_uint32_t flags);
-
+#endif
 /**
  * Create a new pool.
  * @param newpool The pool we have just created.
Index: memory/unix/apr_pools.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
retrieving revision 1.127
diff -u -r1.127 apr_pools.c
--- memory/unix/apr_pools.c     10 Jan 2002 18:52:49 -0000      1.127
+++ memory/unix/apr_pools.c     11 Jan 2002 20:07:28 -0000
@@ -91,6 +91,12 @@
 
 #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
 
+/*
+ * This option prints out the pool creation info
+ * (and info about its children)
+ * when the pool is destroyed.
+ */
+#define APR_POOL_DEBUG_VERBOSE
     
 /*
  * Structures
@@ -161,6 +167,8 @@
 
 #else /* !defined(APR_POOL_DEBUG) */
     debug_node_t         *nodes;
+    const char           *file;
+    int                   line;
 #if APR_HAS_THREADS
     apr_thread_mutex_t *mutex;
 #endif
@@ -887,6 +895,9 @@
     return mem;
 }
 
+/*
+ * (debug)
+ */
 APR_DECLARE(void *) apr_pcalloc(apr_pool_t *pool, apr_size_t size)
 {
     void *mem;
@@ -934,9 +945,32 @@
         free(node);
     }
 }
-
+/*
+ * destroy (debug)
+ */
 APR_DECLARE(void) apr_pool_destroy(apr_pool_t *pool)
 {
+#if defined APR_POOL_DEBUG_VERBOSE
+    apr_file_t *stderr_log=NULL;
+    apr_pool_t *child;
+
+    apr_file_open_stderr(&stderr_log,pool); /* XXX not sure about this one */
+    if (stderr_log) {
+        apr_file_printf(stderr_log,
+            "DEBUG: destroy pool tagged %s created %s:%d\n",
+            pool->tag, pool->file, pool->line);
+        child= pool->child;
+        while (child) {
+            apr_file_printf(stderr_log,
+                "DEBUG:\tpool child tagged %s created %s:%d\n",
+                child->tag, child->file, child->line);
+            child=child->sibling;
+        }
+        apr_file_close(stderr_log);
+    }
+#endif
+
+                                                                               
                       
     apr_pool_clear(pool);
 
     /* Remove the pool from the parents child list */
@@ -961,10 +995,16 @@
     free(pool);
 }
 
-APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool, 
+/*
+ * create (debug)
+ * there is a macro which adds the file/line #
+ */
+APR_DECLARE(apr_status_t) apr_pool_create_ex_dbg(apr_pool_t **newpool, 
                                              apr_pool_t *parent,
                                              apr_abortfunc_t abort_fn,
-                                             apr_uint32_t flags)
+                                             apr_uint32_t flags, 
+                                             const char *file,
+                                             int line)
 {
     apr_pool_t *pool;
 
@@ -1027,6 +1067,9 @@
         pool->sibling = NULL;
         pool->ref = NULL;
     }
+
+    pool->file = file;
+    pool->line = line;
 
     *newpool = pool;
 

Reply via email to