From f18e954626d1bf3d9e1d7666a35776b8296d967a Mon Sep 17 00:00:00 2001 From: glasser Date: Mon, 11 Feb 2008 21:17:39 +0000 Subject: [PATCH] Followup to r27098: fix potential segfault by using pools correctly. * subversion/libsvn_fs_fs/fs_fs.c (svn_fs_fs__rev_get_root): Keep a string out of a pool that might be cleared. Found by: epg Dan Christian git-svn-id: http://svn.collab.net/repos/svn/trunk@29277 612f8ebc-c883-4be0-9ee0-a4e9ef946e3a --- subversion/libsvn_fs_fs/fs_fs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/subversion/libsvn_fs_fs/fs_fs.c b/subversion/libsvn_fs_fs/fs_fs.c index e2de2d2d2..891f61481 100644 --- a/subversion/libsvn_fs_fs/fs_fs.c +++ b/subversion/libsvn_fs_fs/fs_fs.c @@ -2043,7 +2043,7 @@ svn_fs_fs__rev_get_root(svn_fs_id_t **root_id_p, apr_off_t root_offset; svn_fs_id_t *root_id; svn_error_t *err; - const char *rev_str = apr_psprintf(ffd->rev_root_id_cache_pool, "%ld", rev); + const char *rev_str = apr_psprintf(pool, "%ld", rev); svn_fs_id_t *cached_id; SVN_ERR(ensure_revision_exists(fs, rev, pool)); @@ -2077,7 +2077,7 @@ svn_fs_fs__rev_get_root(svn_fs_id_t **root_id_p, SVN_ERR(svn_io_file_close(revision_file, pool)); - /* Cache it */ + /* Make sure our cache size doesn't grow without bounds. */ if (apr_hash_count(ffd->rev_root_id_cache) >= NUM_RRI_CACHE_ENTRIES) { /* In order to only use one pool for the whole cache, we need to @@ -2085,7 +2085,12 @@ svn_fs_fs__rev_get_root(svn_fs_id_t **root_id_p, svn_pool_clear(ffd->rev_root_id_cache_pool); ffd->rev_root_id_cache = apr_hash_make(ffd->rev_root_id_cache_pool); } - apr_hash_set(ffd->rev_root_id_cache, rev_str, APR_HASH_KEY_STRING, + + /* Cache the answer, copying both the key and value into the cache's + pool. */ + apr_hash_set(ffd->rev_root_id_cache, + apr_pstrdup(ffd->rev_root_id_cache_pool, rev_str), + APR_HASH_KEY_STRING, svn_fs_fs__id_copy(root_id, ffd->rev_root_id_cache_pool)); *root_id_p = root_id; -- 2.11.4.GIT