On 8 Jul 2002, Joe Schaefer wrote:

> Write that like this, and I think your leak will
> disappear:
>
>         my $r = Apache::Request->new( shift );
>
> AFAICT, Apache::Request::new is NOT leaking here, since the
> REFCNT of its returned object IS 1.  There might be some
> magic-related bug in perl that causes the assignment to bump
> $r's refcount to 2.  This MIGHT be circumventable with some better
> code in Request.xs, but I really don't know how to fix it.
>
> Until some perl guru enlightens us, as a personal rule I
> try hard to avoid expressions like
>
>   $foo = make_something_out_of($foo);
>
> I realize that this isn't always possible, but it often/usually
> is.  Such advice would serve you well in this case; you could
> even get away with this
>
>   my $r = shift;
>   my $apr = Apache::Request->new($r);
>
> That's not going to leak, either.  At least I hope not :-)

I ended up using something like this and the leak went away.

It seems to me that this might actually be a Perl bug.

If I do this:

 my $x = shift;
 $x = make_something_from($x);

then it seems like the original $x should go out of scope when it is
assigned to, so its refcount should stay at 1.


-dave

/*==================
www.urth.org
we await the New Sun
==================*/

Reply via email to