Christopher Thompson | 14 May 01:19

Minor memory leak in 1.8.6?

Is it not the case that rb_Str_to_inum(str, base, badcheck) in bignum.c 
leaks the memory allocated with ALLOCA_N?

I think it should always be the case that the string has a sentinel and 
so if we end up running that section, there's already a bug, in which 
case this may not be worth worrying about.

VALUE
rb_str_to_inum(str, base, badcheck)
     VALUE str;
     int base;
     int badcheck;
{
     char *s;
     long len;

     StringValue(str);
     if (badcheck) {
	s = StringValueCStr(str);
     }
     else {
	s = RSTRING(str)->ptr;
     }
     if (s) {
	len = RSTRING(str)->len;
	if (s[len]) {		/* no sentinel somehow */
	    char *p = ALLOCA_N(char, len+1);  /* THIS BIT HERE */

	    MEMCPY(p, s, char, len);
	    p[len] = '\0';
(Continue reading)

Nathan Weizenbaum | 14 May 01:54

Re: Minor memory leak in 1.8.6?

I think the point of ALLOCA_N is that the memory is allocated from the 
stack, and thus doesn't have to be explicitly freed.

Christopher Thompson wrote:
> Is it not the case that rb_Str_to_inum(str, base, badcheck) in 
> bignum.c leaks the memory allocated with ALLOCA_N?
>
> I think it should always be the case that the string has a sentinel 
> and so if we end up running that section, there's already a bug, in 
> which case this may not be worth worrying about.
>
>
> VALUE
> rb_str_to_inum(str, base, badcheck)
>     VALUE str;
>     int base;
>     int badcheck;
> {
>     char *s;
>     long len;
>
>     StringValue(str);
>     if (badcheck) {
>     s = StringValueCStr(str);
>     }
>     else {
>     s = RSTRING(str)->ptr;
>     }
>     if (s) {
>     len = RSTRING(str)->len;
(Continue reading)

cthompson | 14 May 02:46

Re: Minor memory leak in 1.8.6?

Ah, of course.  Yes.  I hadn't run in to alloca before.  Strange.

I was definitely wrong, thanks for pointing that out.

On Wed, 14 May 2008 08:54:47 +0900, Nathan Weizenbaum <nex342 <at> gmail.com> wrote:
> I think the point of ALLOCA_N is that the memory is allocated from the
> stack, and thus doesn't have to be explicitly freed.
> 
> Christopher Thompson wrote:
>> Is it not the case that rb_Str_to_inum(str, base, badcheck) in
>> bignum.c leaks the memory allocated with ALLOCA_N?
>>
>> I think it should always be the case that the string has a sentinel
>> and so if we end up running that section, there's already a bug, in
>> which case this may not be worth worrying about.
>>
>>
>> VALUE
>> rb_str_to_inum(str, base, badcheck)
>>     VALUE str;
>>     int base;
>>     int badcheck;
>> {
>>     char *s;
>>     long len;
>>
>>     StringValue(str);
>>     if (badcheck) {
>>     s = StringValueCStr(str);
>>     }
(Continue reading)


Gmane