You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Vlad Georgescu <vg...@gmail.com> on 2007/01/10 23:16:13 UTC
Error leak in libsvn_fs_base/bdb/env.c
bdb_close() in libsvn_fs_base/bdb/env.c currently leaks the pending
errors from BDB if it runs into a DB_RECOVERY error while closing
the database (it ignores the DB_RECOVERY error, but forgets to clear
the list of errors from the error_info structure). The following patch
solves this problem, but I'm not familiar with that code so I thought
I'd run this by the list:
Index: subversion/libsvn_fs_base/bdb/env.c
===================================================================
--- subversion/libsvn_fs_base/bdb/env.c (revision 22952)
+++ subversion/libsvn_fs_base/bdb/env.c (working copy)
@@ -492,6 +492,11 @@
errors, since they're dealt with eventually by BDB itself. */
if (db_err && (!SVN_BDB_AUTO_RECOVER || db_err != DB_RUNRECOVERY))
err = convert_bdb_error(bdb, db_err);
+ else
+ {
+ bdb_error_info_t *error_info = get_error_info(bdb);
+ svn_error_clear(error_info->pending_errors);
+ }
/* Free the environment descriptor. The pool cleanup will do this unless
the cache has already been destroyed. */
--
Vlad
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: Error leak in libsvn_fs_base/bdb/env.c
Posted by Vlad Georgescu <vg...@gmail.com>.
On 1/11/07, Branko Čibej <br...@xbc.nu> wrote:
> Looks O.K. ... but I'd be careful here. It's been a while since I wrote
> that code, but I do recall strange things happening if I wasn't careful
> about the pending errors list.
Ok, I think I now have a better understanding of what's going on. It's
a combination of three things:
a) The apr_threadkey_* APIs do not support destructors on Windows, so
the cleanup_error_info callback, which is supposed to be the last
resort for cleaning up errors, never gets called
b) bdb_close() leaks the pending errors if bdb->env->close() returns DB_RECOVERY
c) svn_fs_bdb__close() is also supposed to clean everything up, but it
does so before calling bdb_close()
I think the simplest fix would be to move the cleanup code in
svn_fs_bdb__close() near the end of the function, after the call to
bdb_close(). This is also the only way we can avoid leaking a
bdb_error_info_t structure, which would be calloc()ed when
db->env->close() invokes our error callback.
Index: subversion/libsvn_fs_base/bdb/env.c
===================================================================
--- subversion/libsvn_fs_base/bdb/env.c (revision 22970)
+++ subversion/libsvn_fs_base/bdb/env.c (working copy)
@@ -515,19 +515,6 @@
cleanup_env_baton(). */
bdb_baton->bdb = NULL;
- /* Note that we only bother with this cleanup if the pool is non-NULL, to
- guard against potential races between this and the cleanup_env cleanup
- callback. It's not clear if that can actually happen, but better safe
- than sorry. */
- if (0 == --bdb_baton->error_info->refcount && bdb->pool)
- {
- svn_error_clear(bdb_baton->error_info->pending_errors);
-#if APR_HAS_THREADS
- free(bdb_baton->error_info);
- apr_threadkey_private_set(NULL, bdb->error_info);
-#endif
- }
-
acquire_cache_mutex();
if (--bdb->refcount != 0)
{
@@ -550,6 +537,19 @@
err = bdb_close(bdb);
release_cache_mutex();
}
+
+ /* Note that we only bother with this cleanup if the pool is non-NULL, to
+ guard against potential races between this and the cleanup_env cleanup
+ callback. It's not clear if that can actually happen, but better safe
+ than sorry. */
+ if (0 == --bdb_baton->error_info->refcount && bdb->pool)
+ {
+ svn_error_clear(bdb_baton->error_info->pending_errors);
+#if APR_HAS_THREADS
+ free(bdb_baton->error_info);
+#endif
+ }
+
return err;
}
--
Vlad
Re: Error leak in libsvn_fs_base/bdb/env.c
Posted by Branko Čibej <br...@xbc.nu>.
Vlad Georgescu wrote:
> bdb_close() in libsvn_fs_base/bdb/env.c currently leaks the pending
> errors from BDB if it runs into a DB_RECOVERY error while closing
> the database (it ignores the DB_RECOVERY error, but forgets to clear
> the list of errors from the error_info structure). The following patch
> solves this problem, but I'm not familiar with that code so I thought
> I'd run this by the list:
>
> Index: subversion/libsvn_fs_base/bdb/env.c
> ===================================================================
> --- subversion/libsvn_fs_base/bdb/env.c (revision 22952)
> +++ subversion/libsvn_fs_base/bdb/env.c (working copy)
> @@ -492,6 +492,11 @@
> errors, since they're dealt with eventually by BDB itself. */
> if (db_err && (!SVN_BDB_AUTO_RECOVER || db_err != DB_RUNRECOVERY))
> err = convert_bdb_error(bdb, db_err);
> + else
> + {
> + bdb_error_info_t *error_info = get_error_info(bdb);
> + svn_error_clear(error_info->pending_errors);
> + }
>
> /* Free the environment descriptor. The pool cleanup will do this unless
> the cache has already been destroyed. */
>
Looks O.K. ... but I'd be careful here. It's been a while since I wrote
that code, but I do recall strange things happening if I wasn't careful
about the pending errors list.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org