[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Detecting unhandled errors

From: C. Michael Pilato <cmpilato_at_collab.net>
Date: 2003-10-11 15:27:50 CEST

"Sander Striker" <striker@apache.org> writes:

> > > * This will catch errors dropped by applications as well as errors we
> > > drop in our own libraries. (At least, if the applications perform an
> > > APR shutdown.) That might be considered a little unfriendly; there are
> > > many cases where an application doesn't need to care about a small
> > > amount of leaked memory, particularly when it only happens a constant
> > > number of times.
>
> That's true. So maybe it needs to be wrapped in another #if block;
> SVN_DEBUG_ERROR_LEAK, or something alike?

This is exactly what I was about to do (except, using
SVN_ERROR_DEBUG). But I don't have time to code or test anything
right now, so here's the patch (obviously sans-#ifdefs). It's just
like what Sander sent, except it also removes the aborts before try to
destroy a child error's pool when that error has been duped into
another pool.

--
* subversion/libsvn_subr/error.c
  (err_abort): New.
  (make_error_internal): Register err_abort() as a cleanup routine for
    new error pools.
  (svn_error_clear, svn_error_compose): Remove err_abort() from the
    cleanup routine list on the error's pool.
Index: subversion/libsvn_subr/error.c
===================================================================
--- subversion/libsvn_subr/error.c	(revision 7373)
+++ subversion/libsvn_subr/error.c	(working copy)
@@ -61,6 +61,14 @@
 }
 
 
+/* Cleanup function for errors.  svn_error_clear () removes this so
+   errors that are properly handled *don't* hit this code. */
+static apr_status_t err_abort (void *data)
+{
+  abort();
+}
+
+
 static svn_error_t *
 make_error_internal (apr_status_t apr_err,
                      svn_error_t *child)
@@ -71,8 +79,12 @@
   /* Reuse the child's pool, or create our own. */
   if (child)
     pool = child->pool;
-  else if (apr_pool_create (&pool, NULL))
-    abort ();
+  else
+    {
+      if (apr_pool_create (&pool, NULL))
+        abort ();
+      apr_pool_cleanup_register(pool, NULL, err_abort, NULL);
+    }
 
   /* Create the new error structure */
   new_error = (svn_error_t *) apr_pcalloc (pool, sizeof (*new_error));
@@ -157,6 +169,7 @@
     }
 
   /* Destroy the new error chain. */
+  apr_pool_cleanup_kill (oldpool, NULL, err_abort);
   apr_pool_destroy (oldpool);
 }
 
@@ -165,7 +178,10 @@
 svn_error_clear (svn_error_t *err)
 {
   if (err)
-    apr_pool_destroy (err->pool);
+    {
+      apr_pool_cleanup_kill (err->pool, NULL, err_abort);
+      apr_pool_destroy (err->pool);
+    }
 }
 
 
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Oct 11 15:28:56 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.