[#413] Should we check alloca ret val? — Michal Rokos <m.rokos@...>
Hi,
7 messages
2002/09/03
[#441] Patch to add a Module#const_missing method — JanArne.Petersen@... (Jan Arne Petersen)
Hi,
11 messages
2002/09/05
[#443] Re: Patch to add a Module#const_missing method
— matz@... (Yukihiro Matsumoto)
2002/09/06
Hi,
[#444] io_write()/fwrite() and EINTR on Solaris — Jos Backus <jos@...>
I am encountering a problem similar to the one mentioned here,
19 messages
2002/09/06
[#453] Re: io_write()/fwrite() and EINTR on Solaris
— nobu.nokada@...
2002/09/08
Hi,
[#454] Re: io_write()/fwrite() and EINTR on Solaris
— matz@... (Yukihiro Matsumoto)
2002/09/09
Hi
[#469] Re: io_write()/fwrite() and EINTR on Solaris
— Jos Backus <jos@...>
2002/09/09
On Mon, Sep 09, 2002 at 03:55:13PM +0900, Yukihiro Matsumoto wrote:
[#479] Re: io_write()/fwrite() and EINTR on Solaris
— Jos Backus <jos@...>
2002/09/10
On Tue, Sep 10, 2002 at 01:04:10AM +0900, Jos Backus wrote:
[#492] Re: io_write()/fwrite() and EINTR on Solaris
— Jos Backus <jos@...>
2002/09/21
On Wed, Sep 11, 2002 at 02:23:33AM +0900, Jos Backus wrote:
[#495] Re: io_write()/fwrite() and EINTR on Solaris
— nobu.nokada@...
2002/09/21
Hi,
[#496] Re: io_write()/fwrite() and EINTR on Solaris
— Jos Backus <jos@...>
2002/09/21
Hello,
[#564] Re: io_write()/fwrite() and EINTR on Solaris
— Jos Backus <jos@...>
2002/11/06
On Sun, Sep 22, 2002 at 04:24:31AM +0900, Jos Backus wrote:
[#566] Re: io_write()/fwrite() and EINTR on Solaris
— nobu.nokada@...
2002/11/07
Hi,
[#567] Re: io_write()/fwrite() and EINTR on Solaris
— Jos Backus <jos@...>
2002/11/07
On Thu, Nov 07, 2002 at 01:43:03PM +0900, nobu.nokada@softhome.net wrote:
[#568] Re: io_write()/fwrite() and EINTR on Solaris
— nobu.nokada@...
2002/11/07
Hi,
[#569] Re: io_write()/fwrite() and EINTR on Solaris
— Jos Backus <jos@...>
2002/11/07
On Thu, Nov 07, 2002 at 03:49:51PM +0900, nobu.nokada@softhome.net wrote:
[#449] ruby.h, string.c — Michal Rokos <m.rokos@...>
Hello,
7 messages
2002/09/06
[#459] Parse.y — Michal Rokos <m.rokos@...>
Hi,
6 messages
2002/09/09
[#461] Related to [Memleak] in sprintf.c — Michal Rokos <m.rokos@...>
Hi,
5 messages
2002/09/09
[#508] can java applications invoke ruby scripts?? — "John Davis" <javaccnews@...>
I want to know if Java applications can invoke ruby scripts?? In other
8 messages
2002/09/26
Re: [Fix] Dir mem leak
From:
matz@... (Yukihiro Matsumoto)
Date:
2002-09-10 16:17:02 UTC
List:
ruby-core #478
Hi,
In message "Re: [Fix] Dir mem leak"
on 02/09/10, nobu.nokada@softhome.net <nobu.nokada@softhome.net> writes:
|glob_helper() calls arbitrary functions, even ruby blocks
|passed to Dir.glob, so this function must be exception safe.
|Also, closedir() must be ensured.
I haven't noticed that. How hard to work on non GC environment.
|I thought 2 approaches, 1) wrap resources by VALUE, 2) use
|rb_protect() all *func and recursive call, but feel the latter
|is too complex.
The latter should not be too complex. Here's my modifies. not
tested. Maybe it's still incomplete though.
Index: dir.c
===================================================================
RCS file: /src/ruby/dir.c,v
retrieving revision 1.71
diff -u -1 -r1.71 dir.c
--- dir.c 2002/06/15 10:24:38 1.71
+++ dir.c 2002/09/10 16:16:21
@@ -655,3 +655,34 @@
-static void
+struct glob_args {
+ void (*func) _((const char*, VALUE));
+ const char *c;
+ VALUE v;
+};
+
+static VALUE
+glob_func_caller(args)
+ struct glob_args *args;
+{
+ (*args->func)(args->c, args->v);
+ return Qnil;
+}
+
+static int
+glob_call_func(func, path, arg)
+ void (*func) _((const char*, VALUE));
+ const char *path;
+ VALUE arg;
+{
+ int status;
+ struct glob_args args;
+
+ args.func = func;
+ args.c = path;
+ args.v = arg;
+
+ rb_protect(glob_func_caller, (VALUE)&args, &status);
+ return status;
+}
+
+static int
glob_helper(path, sub, flags, func, arg)
@@ -665,2 +696,3 @@
char *p, *m;
+ int status = 0;
@@ -674,3 +706,4 @@
if (lstat(path, &st) == 0) {
- (*func)(path, arg);
+ status = glob_call_func(func, path, arg);
+ if (status) return status;
}
@@ -681,6 +714,6 @@
}
- return;
+ return 0;
}
- while (p) {
+ while (p && !status) {
if (*p == '/') p++;
@@ -706,2 +739,3 @@
free(base);
+ free(magic);
break;
@@ -714,4 +748,5 @@
sprintf(buf, "%s%s", base, *base ? m : m+1);
- glob_helper(buf, buf+n, flags, func, arg);
+ status = glob_helper(buf, buf+n, flags, func, arg);
free(buf);
+ if (status) goto finalize;
}
@@ -721,2 +756,3 @@
free(base);
+ free(magic);
break;
@@ -726,2 +762,3 @@
free(base);
+ free(magic);
break;
@@ -749,3 +786,5 @@
strcpy(t+3, m);
- glob_helper(buf, t, flags, func, arg);
+ status = glob_helper(buf, t, flags, func, arg);
+ free(buf);
+ if (status) goto finalize;
}
@@ -758,4 +797,4 @@
if (!m) {
- (*func)(buf, arg);
- free(buf);
+ status = glob_call_func(func, path, arg);
+ if (status) goto finalize;
continue;
@@ -768,2 +807,3 @@
}
+ finalize:
closedir(dirp);
@@ -773,15 +813,17 @@
while (link) {
- if (stat(link->path, &st) == 0) {
- if (S_ISDIR(st.st_mode)) {
- int len = strlen(link->path);
- int mlen = strlen(m);
- char *t = ALLOC_N(char, len+mlen+1);
-
- sprintf(t, "%s%s", link->path, m);
- glob_helper(t, t+len, flags, func, arg);
- free(t);
+ if (status == 0) {
+ if (stat(link->path, &st) == 0) {
+ if (S_ISDIR(st.st_mode)) {
+ int len = strlen(link->path);
+ int mlen = strlen(m);
+ char *t = ALLOC_N(char, len+mlen+1);
+
+ sprintf(t, "%s%s", link->path, m);
+ status = glob_helper(t, t+len, flags, func, arg);
+ free(t);
+ }
}
- }
- else {
- rb_sys_warning(link->path);
+ else {
+ rb_sys_warning(link->path);
+ }
}
@@ -797,2 +839,3 @@
}
+ return status;
}
@@ -806,3 +849,4 @@
{
- glob_helper(path, 0, flags, func, arg);
+ int status = glob_helper(path, 0, flags, func, arg);
+ if (status) rb_jump_tag(status);
}