From: "H.Yamamoto" Date: 2004-09-06T12:04:53+09:00 Subject: Re: [PATCH] dir.c --- Dir.chdir error handling 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);