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

[PATCH] Fix memory leak like situation when parsing a svn_config_t object repeatedly

From: Bernd Rinn <bernd_at_sdf.lonestar.org>
Date: 2005-07-24 01:24:57 CEST

When using the functions svn_config_enumerate() and
svn_config_enumerate_sections() in libsvn_subr repeatedly on the same cfg, I
ran into the problem that memory usage increased with every function
call. Please note that I am only parsing the configuration, not modifying it
in any way. For the use case that I have in mind this behavior is
indistinguishable from a memory leak.

The problem turned out to be in the system calls of apr_hash_first(). When I go
to the apr source tables/apr_hash.c (I have checked versions 0.9.0 - 1.1.1,
all the same with respect to what I want to point out), I find:

APR_DECLARE(apr_hash_index_t *) apr_hash_first(apr_pool_t *p, apr_hash_t *ht)
    apr_hash_index_t *hi;
    if (p)
        hi = apr_palloc(p, sizeof(*hi));
        hi = &ht->iterator;

    hi->ht = ht;
    hi->index = 0;
    hi->this = NULL;
    hi->next = NULL;
    return apr_hash_next(hi);

Here you can see that memory is allocated only if p != NULL, otherwise the
attribute 'iterator' of apr_pool_t is used which is perfectly fine from what I
can see.

Thus I suggest to replace the function call in svn_config_enumerate_sections()

  apr_hash_first (cfg->x_pool, cfg->sections)


  apr_hash_first(NULL, cfg->sections)

Same with svn_config_enumerate(). I have verified that this change fixes my
use case and keeps the memory usage constant when calling
svn_config_enumerate_*() repeatedly with the same cfg.

The patch is trivial and applies cleanly to both, trunk and branches/1.2.x. So
I would like to ask you if you deem it appropriate for inclusion into subversion

Here is the log message:

Fix memory leak like situation when parsing a svn_config_t object

Patch by: Bernd Rinn <bernd@sdf.lonestar.org>

* subversion/libsvn_subr/config.c
  (svn_config_enumerate): replace the x_pool of cfg by NULL in call to
  (svn_config_sections): dito.


To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Received on Sun Jul 24 01:27:09 2005

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.