[#3419] Valgrind analysis of [BUG] unknown node type 0 — Andrew Walrond <andrew@...>

Hello list,

19 messages 2004/09/17
[#3422] Re: Valgrind analysis of [BUG] unknown node type 0 — ts <decoux@...> 2004/09/17

>>>>> "A" == Andrew Walrond <andrew@walrond.org> writes:

[#3423] Re: Valgrind analysis of [BUG] unknown node type 0 — Andrew Walrond <andrew@...> 2004/09/17

On Friday 17 Sep 2004 12:01, ts wrote:

[#3424] Re: Valgrind analysis of [BUG] unknown node type 0 — ts <decoux@...> 2004/09/17

>>>>> "A" == Andrew Walrond <andrew@walrond.org> writes:

[#3425] Re: Valgrind analysis of [BUG] unknown node type 0 — Andrew Walrond <andrew@...> 2004/09/17

On Friday 17 Sep 2004 12:37, ts wrote:

[#3426] Re: Valgrind analysis of [BUG] unknown node type 0 — ts <decoux@...> 2004/09/17

>>>>> "A" == Andrew Walrond <andrew@walrond.org> writes:

[#3428] Re: Valgrind analysis of [BUG] unknown node type 0 — Andrew Walrond <andrew@...> 2004/09/17

On Friday 17 Sep 2004 13:05, ts wrote:

[#3429] Re: Valgrind analysis of [BUG] unknown node type 0 — ts <decoux@...> 2004/09/17

>>>>> "A" == Andrew Walrond <andrew@walrond.org> writes:

Re: [PATCH] dir.c --- Dir.chdir error handling

From: "H.Yamamoto" <ocean@...2.ccsnet.ne.jp>
Date: 2004-09-06 03:04:53 UTC
List: ruby-core #3351
Hello.

>     if (rb_block_given_p()) {
> 	char *cwd = my_getcwd();
>	dir_chdir(dist);
> 	chdir_blocking++;
> 	if (chdir_thread == Qnil)
> 	    chdir_thread = rb_thread_current();
> 	return rb_ensure(rb_yield, path, chdir_restore, (VALUE)cwd);
>     }
>     dir_chdir(dist);

I think memory `cwd' leaks when dir_chdir raised exception. (chdir_restore has same issue)

I created kind of patch, but copy tmp => cwd looks a little agry....

Index: dir.c
===================================================================
RCS file: /var/cvs/src/ruby/dir.c,v
retrieving revision 1.125
diff -u -w -b -p -r1.125 dir.c
--- dir.c	19 Aug 2004 07:33:15 -0000	1.125
+++ dir.c	6 Sep 2004 02:59:41 -0000
@@ -689,13 +689,12 @@ static VALUE chdir_thread = Qnil;
 
 static VALUE
 chdir_restore(path)
-    char *path;
+    VALUE path;
 {
     chdir_blocking--;
     if (chdir_blocking == 0)
 	chdir_thread = Qnil;
-    dir_chdir(path);
-    free(path);
+    dir_chdir(RSTRING(path)->ptr);
     return Qnil;
 }
 
@@ -766,12 +765,13 @@ dir_s_chdir(argc, argv, obj)
     }
 
     if (rb_block_given_p()) {
-	char *cwd = my_getcwd();
+	char *tmp = my_getcwd();
+	VALUE cwd = rb_str_new2(tmp); free(tmp);
+	dir_chdir(dist);
 	chdir_blocking++;
 	if (chdir_thread == Qnil)
 	    chdir_thread = rb_thread_current();
-	dir_chdir(dist);
-	return rb_ensure(rb_yield, path, chdir_restore, (VALUE)cwd);
+	return rb_ensure(rb_yield, path, chdir_restore, cwd);
     }
     dir_chdir(dist);



In This Thread