[#237] object.c ruby.h (fwd) — Robert Skarwecki <skaav@...>

Hello everybody,

42 messages 2002/07/24
[#239] Re: [PATCH] object.c ruby.h (fwd) — GOTO Kentaro <gotoken@...> 2002/07/24

At Thu, 25 Jul 2002 00:02:28 +0900,

[#240] Re: [PATCH] object.c ruby.h (fwd) — Dave Thomas <Dave@...> 2002/07/24

GOTO Kentaro <gotoken@notwork.org> writes:

[#246] Re: [PATCH] object.c ruby.h (fwd) — GOTO Kentaro <gotoken@...> 2002/07/25

At Thu, 25 Jul 2002 05:05:46 +0900,

[#247] Re: [PATCH] object.c ruby.h (fwd) — Dave Thomas <Dave@...> 2002/07/25

GOTO Kentaro <gotoken@notwork.org> writes:

[#248] Re: [PATCH] object.c ruby.h (fwd) — nobu.nokada@... 2002/07/25

Hi,

[#249] Re: [PATCH] object.c ruby.h (fwd) — Dave Thomas <Dave@...> 2002/07/25

nobu.nokada@softhome.net writes:

[#250] Re: [PATCH] object.c ruby.h (fwd) — nobu.nokada@... 2002/07/25

Hi,

[#252] Re: [PATCH] object.c ruby.h (fwd) — GOTO Kentaro <gotoken@...> 2002/07/25

At Fri, 26 Jul 2002 03:11:02 +0900,

[#253] Re: [PATCH] object.c ruby.h (fwd) — Dave Thomas <Dave@...> 2002/07/25

GOTO Kentaro <gotoken@notwork.org> writes:

Re: Mem leaks in rb_str_become?

From: matz@... (Yukihiro Matsumoto)
Date: 2002-07-04 15:28:07 UTC
List: ruby-core #200
Hi,

In message "Mem leaks in rb_str_become?"
    on 02/07/04, Michal Rokos <m.rokos@sh.cvut.cz> writes:

|	I'm not sure is following code doesn't mem leaks...

|-    VALUE str = rb_obj_alloc(klass);
|-
|+    VALUE str;
|+    
|     if (len < 0) {
| 	rb_raise(rb_eArgError, "negative string size (or size too big)");
|     }
|-
|+    
|+    str = rb_obj_alloc(klass);

OK.

|     if (ptr) {
| 	memcpy(RSTRING(str)->ptr, ptr, len);
|+    } else {
|+	memset(RSTRING(str)->ptr, '\0', len);
|     }

OK, but using MEMZERO() macro.

| str_new3(klass, str)
|     VALUE klass, str;
| {
|-    VALUE str2 = rb_obj_alloc(klass);
|-
|+    VALUE str2;
|+    
|+    Check_Type(str, T_STRING);

str should alway be T_STRING, so no check is needed here.

|+    Check_Type(orig, T_STRING);

ditto.

|-    str = rb_str_buf_new(len + STR_BUF_MIN_SIZE);
|+    str = rb_str_buf_new(len);

OK.

|     if (NIL_P(str2)) {
|-	RSTRING(str)->ptr = 0;
|+	RSTRING(str)->ptr = 0; /* FIXME: MEM LEAKs here ???*/

Yes.  It was leaking.  I should have moved 

    if (!FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr);

before updating RSTRING(str)->ptr.

Thank you for the changes.  I will commit them.

							matz.

In This Thread

Prev Next