1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* dir.c (rb_glob2, rb_glob, push_globs, push_braces, rb_push_glob):

fix memory leak to occur when block is interrupted in Dir.glob.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ocean 2004-04-12 01:45:27 +00:00
parent ac419876d5
commit 4c4d155e3d
2 changed files with 27 additions and 11 deletions

View file

@ -1,3 +1,8 @@
Mon Apr 12 10:39:50 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* dir.c (rb_glob2, rb_glob, push_globs, push_braces, rb_push_glob):
fix memory leak to occur when block is interrupted in Dir.glob.
Sun Apr 11 19:10:13 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> Sun Apr 11 19:10:13 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (require_libraries): restore source file/line after * ruby.c (require_libraries): restore source file/line after

33
dir.c
View file

@ -1325,7 +1325,7 @@ glob_helper(path, dirsep, exist, isdir, beg, end, flags, func, arg)
return status; return status;
} }
static void static int
rb_glob2(path, flags, func, arg) rb_glob2(path, flags, func, arg)
const char *path; const char *path;
int flags; int flags;
@ -1362,7 +1362,7 @@ rb_glob2(path, flags, func, arg)
free(buf); free(buf);
if (status) rb_jump_tag(status); return status;
} }
void void
@ -1371,7 +1371,9 @@ rb_glob(path, func, arg)
void (*func) _((const char*, VALUE)); void (*func) _((const char*, VALUE));
VALUE arg; VALUE arg;
{ {
rb_glob2(path, 0, func, arg); int status = rb_glob2(path, 0, func, arg);
if (status) rb_jump_tag(status);
} }
static void static void
@ -1389,16 +1391,16 @@ push_pattern(path, ary)
} }
} }
static void static int
push_globs(ary, s, flags) push_globs(ary, s, flags)
VALUE ary; VALUE ary;
const char *s; const char *s;
int flags; int flags;
{ {
rb_glob2(s, flags, push_pattern, ary); return rb_glob2(s, flags, push_pattern, ary);
} }
static void static int
push_braces(ary, s, flags) push_braces(ary, s, flags)
VALUE ary; VALUE ary;
const char *s; const char *s;
@ -1408,6 +1410,7 @@ push_braces(ary, s, flags)
const char *p, *t; const char *p, *t;
const char *lbrace, *rbrace; const char *lbrace, *rbrace;
int nest = 0; int nest = 0;
int status = 0;
p = s; p = s;
lbrace = rbrace = 0; lbrace = rbrace = 0;
@ -1441,13 +1444,16 @@ push_braces(ary, s, flags)
} }
memcpy(b, t, p-t); memcpy(b, t, p-t);
strcpy(b+(p-t), Next(rbrace)); strcpy(b+(p-t), Next(rbrace));
push_braces(ary, buf, flags); status = push_braces(ary, buf, flags);
if (status) break;
} }
free(buf); free(buf);
} }
else { else {
push_globs(ary, s, flags); status = push_globs(ary, s, flags);
} }
return status;
} }
#define isdelim(c) ((c)=='\0') #define isdelim(c) ((c)=='\0')
@ -1460,6 +1466,7 @@ rb_push_glob(str, flags)
char *buf; char *buf;
const char *t; const char *t;
int nest, maxnest; int nest, maxnest;
int status = 0;
int escape = !(flags & FNM_NOESCAPE); int escape = !(flags & FNM_NOESCAPE);
VALUE ary; VALUE ary;
@ -1485,20 +1492,24 @@ rb_push_glob(str, flags)
p++; p++;
if (p == pend || isdelim(*p)) break; if (p == pend || isdelim(*p)) break;
} }
p = Next(p); Inc(p);
} }
memcpy(buf, t, p - t); memcpy(buf, t, p - t);
buf[p - t] = '\0'; buf[p - t] = '\0';
if (maxnest == 0) { if (maxnest == 0) {
push_globs(ary, buf, flags); status = push_globs(ary, buf, flags);
if (status) break;
} }
else if (nest == 0) { else if (nest == 0) {
push_braces(ary, buf, flags); status = push_braces(ary, buf, flags);
if (status) break;
} }
/* else unmatched braces */ /* else unmatched braces */
} }
free(buf); free(buf);
if (status) rb_jump_tag(status);
return ary; return ary;
} }