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

[PATCH 1] Allocating large buffers on the stack was: Re: Subversion 1.2.0 RC3 (final candidate) on Monday?

From: Patrick Mayweg <mayweg_at_qint.de>
Date: 2005-05-08 16:03:58 CEST

Hi,
this patch removes all but one of the SVN_STREAM_CHUNK_SIZE buffers from
the stack and use the pool instead. This fixes the stack overflow for
the javahl binding on windows.
Regards,
Patrick Mayweg

Log message:
[[[
Use the pool memory instead of stack memory for big buffers in all
cases, which
do not need an interface change.

* subversion/libsvn_ra_dav/util.c
  (parse_spool_file) : use pool memory for big buffer.

* subversion/libsvn_repos/reporter.c
  (compare_files) : use pool memory for big buffers.

* subversion/libsvn_repos/delta.c
  (compare_files) : use pool memory for big buffers.

* subversion/libsvn_subr/stream.c
  (svn_stream_copy) : use pool memory for big buffer.
]]]

Patrick Mayweg wrote:

> Hi Philip,
>
> Philip Martin wrote:
>
>> "Peter N. Lundblad" <peter@famlundblad.se> writes:
>>
>>
>>
>>> Ouch! Putting vars of those sizes on the stack isn't very friendly.
>>> Just
>>> allocate it out of a pool instead.
>>>
>>> (Saying this without having investigated in detail, but I can't
>>> imagine it
>>> should be a problem.)
>>>
>>
>>
>>
>> Look at this:
>>
>>
> This is the only case, where a pool is not available.
>
>> svn_error_t *
>> svn_subst_translate_stream (svn_stream_t *s, /* src stream */
>> svn_stream_t *d, /* dst stream */
>> const char *eol_str,
>> svn_boolean_t repair,
>> const svn_subst_keywords_t *keywords,
>> svn_boolean_t expand)
>> {
>> char buf[SVN_STREAM_CHUNK_SIZE + 1];
>> const char *p, *interesting;
>>
>> There is no readily available pool, and neither svn_stream_t nor
>> svn_subst_keywords_t provides one. There is a void* baton in
>> svn_stream_t but svn_subst_translate_stream can't really make any
>> assumptions about it.
>>
>>
> All callers of this function have a pool available. If I could extend
> the interface by a pool parameter, I could change that case too.
> Patrick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: dev-help@subversion.tigris.org
>

Index: subversion/libsvn_ra_dav/util.c
===================================================================
--- subversion/libsvn_ra_dav/util.c (revision 14544)
+++ subversion/libsvn_ra_dav/util.c (working copy)
@@ -502,7 +502,7 @@
 {
   apr_file_t *spool_file;
   svn_stream_t *spool_stream;
- char buf[SVN_STREAM_CHUNK_SIZE];
+ char *buf = apr_palloc(pool, SVN_STREAM_CHUNK_SIZE);
   apr_size_t len;
   
   SVN_ERR( svn_io_file_open(&spool_file, spool_file_name,
Index: subversion/libsvn_repos/reporter.c
===================================================================
--- subversion/libsvn_repos/reporter.c (revision 14544)
+++ subversion/libsvn_repos/reporter.c (working copy)
@@ -448,7 +448,7 @@
   svn_filesize_t size1, size2;
   unsigned char digest1[APR_MD5_DIGESTSIZE], digest2[APR_MD5_DIGESTSIZE];
   svn_stream_t *stream1, *stream2;
- char buf1[SVN_STREAM_CHUNK_SIZE], buf2[SVN_STREAM_CHUNK_SIZE];
+ char *buf1, *buf2;
   apr_size_t len1, len2;
 
   /* If the filesystem claims the things haven't changed, then they
@@ -487,6 +487,8 @@
   SVN_ERR (svn_fs_file_contents (&stream1, root1, path1, pool));
   SVN_ERR (svn_fs_file_contents (&stream2, root2, path2, pool));
 
+ buf1 = apr_palloc (pool, SVN_STREAM_CHUNK_SIZE);
+ buf2 = apr_palloc (pool, SVN_STREAM_CHUNK_SIZE);
   do
     {
       len1 = len2 = SVN_STREAM_CHUNK_SIZE;
Index: subversion/libsvn_repos/delta.c
===================================================================
--- subversion/libsvn_repos/delta.c (revision 14544)
+++ subversion/libsvn_repos/delta.c (working copy)
@@ -616,7 +616,7 @@
   svn_filesize_t size1, size2;
   unsigned char digest1[APR_MD5_DIGESTSIZE], digest2[APR_MD5_DIGESTSIZE];
   svn_stream_t *stream1, *stream2;
- char buf1[SVN_STREAM_CHUNK_SIZE], buf2[SVN_STREAM_CHUNK_SIZE];
+ char *buf1, *buf2;
   apr_size_t len1, len2;
 
   /* If the filesystem claims the things haven't changed, then they
@@ -655,6 +655,8 @@
   SVN_ERR (svn_fs_file_contents (&stream1, root1, path1, pool));
   SVN_ERR (svn_fs_file_contents (&stream2, root2, path2, pool));
 
+ buf1 = apr_palloc (pool, SVN_STREAM_CHUNK_SIZE);
+ buf2 = apr_palloc (pool, SVN_STREAM_CHUNK_SIZE);
   do
     {
       len1 = len2 = SVN_STREAM_CHUNK_SIZE;
Index: subversion/libsvn_subr/stream.c
===================================================================
--- subversion/libsvn_subr/stream.c (revision 14544)
+++ subversion/libsvn_subr/stream.c (working copy)
@@ -183,7 +183,7 @@
 svn_error_t *svn_stream_copy (svn_stream_t *from, svn_stream_t *to,
                               apr_pool_t *pool)
 {
- char buf[SVN_STREAM_CHUNK_SIZE];
+ char *buf = apr_palloc (pool, SVN_STREAM_CHUNK_SIZE);
   apr_size_t len;
 
   /* Read and write chunks until we get a short read, indicating the

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun May 8 16:04:32 2005

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