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

Re: Memory leak in svn_ra_get_file() with svn+ssh://?

From: David Glasser <glasser_at_davidglasser.net>
Date: 2007-10-06 02:42:17 CEST

On 10/2/07, Philipp Marek <philipp@marek.priv.at> wrote:
> Hello everybody,
>
> I think there's a memory leak in svn_ra_get_file() or the svn+ssh RA layer.
> FSVS (http://fsvs.tigris.org) uses svn_ra_get_file() eg. for reverts -
> to fetch a clean copy of a file from the repository.

Thanks for the bug report! It does in fact look to me like there is a
memory leak in libsvn_ra_svn/client.c(ra_svn_get_file). I'll commit
this as soon as tests finish passing (hopefully this will be before I
go home today).

[[[
Fix unbounded memory usage in ra_svn implementation of
svn_ra_get_file. ('svn cat'

Found by: pmarek

* subversion/libsvn_ra_svn/client.c
  (ra_svn_get_file): Introduce an iterpool into the loop that reads
   file contents from the server 4K at a time.
]]]

Index: subversion/libsvn_ra_svn/client.c
===================================================================
--- subversion/libsvn_ra_svn/client.c (revision 26963)
+++ subversion/libsvn_ra_svn/client.c (working copy)
@@ -877,6 +877,7 @@ static svn_error_t *ra_svn_get_file(svn_
   unsigned char digest[APR_MD5_DIGESTSIZE];
   const char *expected_checksum, *hex_digest;
   apr_md5_ctx_t md5_context;
+ apr_pool_t *iterpool;

   SVN_ERR(svn_ra_svn_write_cmd(conn, pool, "get-file", "c(?r)bb", path,
                                rev, (props != NULL), (stream != NULL)));
@@ -898,9 +899,11 @@ static svn_error_t *ra_svn_get_file(svn_
     apr_md5_init(&md5_context);

   /* Read the file's contents. */
+ iterpool = svn_pool_create(pool);
   while (1)
     {
- SVN_ERR(svn_ra_svn_read_item(conn, pool, &item));
+ svn_pool_clear(iterpool);
+ SVN_ERR(svn_ra_svn_read_item(conn, iterpool, &item));
       if (item->kind != SVN_RA_SVN_STRING)
         return svn_error_create(SVN_ERR_RA_SVN_MALFORMED_DATA, NULL,
                                 _("Non-string as part of file contents"));
@@ -914,6 +917,8 @@ static svn_error_t *ra_svn_get_file(svn_
       SVN_ERR(svn_stream_write(stream, item->u.string->data,
                                &item->u.string->len));
     }
+ svn_pool_destroy(iterpool);
+
   SVN_ERR(svn_ra_svn_read_cmd_response(conn, pool, ""));

   if (expected_checksum)

-- 
David Glasser | glasser_at_davidglasser.net | http://www.davidglasser.net/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Oct 6 02:42:26 2007

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