Home  |  Linux  | Mysql  | PHP  | XML
From:Sisyphus Date:Thu Jul 31 07:57:28 2008
Subject:Re: Allocating a char* and returning to Perl from a C function
----- Original Message ----- 
From: "Paulo Filipe Andrade" <pfca@mega.ist.utl.pt>
.
.
>
> That's it. I got it working like the example above.
> I just have a couple of questions more about memory leaks.
>
> 1 - If you create an SV like so:
> outsv = newSV(lenX);
> and then use SvCUR_set to set the string length
> SvCUR_set(outsv, lenY);
> where lenY < lenX.
> When outsv is freed the whole buffer is still release right? SvCUR 
> doesn't matter, right?

As far as freeing goes, you may be right.
But if you don't set set CUR it defaults to zero - which has disastrous 
effects on the PV that is actually being stored in the scalar.

It's not hard to test - just comment out the line 'SvCUR_set(outsv, len);' 
and you'll soon see :-)

> 2- Finally, do I need to call sv_2mortal on outsv before returning it?

No. If I do that I get an "Attempt to free unreferenced scalar..." warning.

Cheers,
Rob 

Navigate in group perl.inline at sever nntp.perl.org
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants