You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by st...@apache.org on 2004/01/29 03:44:33 UTC

cvs commit: modperl-2.0/xs/APR/Brigade APR__Brigade.h

stas        2004/01/28 18:44:33

  Modified:    xs/APR/Brigade APR__Brigade.h
  Log:
  avoid a memory leak if flatten() croaks by moving newSV until after croak.
  
  Revision  Changes    Path
  1.9       +2 -1      modperl-2.0/xs/APR/Brigade/APR__Brigade.h
  
  Index: APR__Brigade.h
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/xs/APR/Brigade/APR__Brigade.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -u -r1.8 -r1.9
  --- APR__Brigade.h	29 Jan 2004 01:26:49 -0000	1.8
  +++ APR__Brigade.h	29 Jan 2004 02:44:33 -0000	1.9
  @@ -106,7 +106,7 @@
       apr_bucket_brigade *bb;
       apr_size_t length;
       apr_status_t status;
  -    SV *data = newSV(0);
  +    SV *data;
   
       mpxs_usage_va_1(bb, "$bb->flatten([$length])");
   
  @@ -125,6 +125,7 @@
           length = (apr_size_t)actual;
       }
   
  +    data = newSV(0);
       mpxs_sv_grow(data, length);
   
       status = apr_brigade_flatten(bb, SvPVX(data), &length);
  
  
  

Re: cvs commit: modperl-2.0/xs/APR/Brigade APR__Brigade.h

Posted by Stas Bekman <st...@stason.org>.
stas@apache.org wrote:
> stas        2004/01/28 18:44:33
> 
>   Modified:    xs/APR/Brigade APR__Brigade.h
>   Log:
>   avoid a memory leak if flatten() croaks by moving newSV until after croak.

Watch out for the clear and hidden behind macros croak calls after perl vars 
were created w/o being made mortal. If the function croaks we get a memory 
leak. So either move the creation after the croak, or make the variable mortal 
before the croak.

I think we still have several places that have this problem (probably most are 
my fault).

>   -    SV *data = newSV(0);
>   +    SV *data;
>    
>        mpxs_usage_va_1(bb, "$bb->flatten([$length])");
>    
>   @@ -125,6 +125,7 @@
>            length = (apr_size_t)actual;
>        }
>    
>   +    data = newSV(0);
>        mpxs_sv_grow(data, length);

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org