From 72ba13aa8e86eb7f12bd17737a689ad2ec214036 Mon Sep 17 00:00:00 2001 From: ko1 Date: Sun, 8 Jun 2008 10:01:40 +0000 Subject: * array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c, enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c, io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c, string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c, vm.c, gc.c: allocated memory objects by xmalloc (ruby_xmalloc) should be freed by xfree (ruby_xfree). * ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c, ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c, ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c, ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c, ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- dir.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'dir.c') diff --git a/dir.c b/dir.c index 7958d685cd..55783b1470 100644 --- a/dir.c +++ b/dir.c @@ -349,9 +349,9 @@ free_dir(struct dir_data *dir) { if (dir) { if (dir->dir) closedir(dir->dir); - if (dir->path) free(dir->path); + if (dir->path) xfree(dir->path); } - free(dir); + xfree(dir); } static VALUE dir_close(VALUE); @@ -382,7 +382,7 @@ dir_initialize(VALUE dir, VALUE dirname) FilePathValue(dirname); Data_Get_Struct(dir, struct dir_data, dp); if (dp->dir) closedir(dp->dir); - if (dp->path) free(dp->path); + if (dp->path) xfree(dp->path); dp->dir = NULL; dp->path = NULL; dp->dir = opendir(RSTRING_PTR(dirname)); @@ -780,7 +780,7 @@ dir_s_chdir(int argc, VALUE *argv, VALUE obj) struct chdir_data args; char *cwd = my_getcwd(); - args.old_path = rb_tainted_str_new2(cwd); free(cwd); + args.old_path = rb_tainted_str_new2(cwd); xfree(cwd); args.new_path = path; args.done = Qfalse; return rb_ensure(chdir_yield, (VALUE)&args, chdir_restore, (VALUE)&args); @@ -811,7 +811,7 @@ dir_s_getwd(VALUE dir) path = my_getcwd(); cwd = rb_tainted_str_new2(path); - free(path); + xfree(path); return cwd; } @@ -917,6 +917,7 @@ sys_warning_1(const char* mesg) #define GLOB_ALLOC(type) (type *)malloc(sizeof(type)) #define GLOB_ALLOC_N(type, n) (type *)malloc(sizeof(type) * (n)) +#define GLOB_FREE(ptr) free(ptr) #define GLOB_JUMP_TAG(status) ((status == -1) ? rb_memerror() : rb_jump_tag(status)) /* @@ -1081,7 +1082,7 @@ glob_make_pattern(const char *p, int flags) const char *m = find_dirsep(p, flags); char *buf = GLOB_ALLOC_N(char, m-p+1); if (!buf) { - free(tmp); + GLOB_FREE(tmp); goto error; } memcpy(buf, p, m-p); @@ -1123,8 +1124,8 @@ glob_free_pattern(struct glob_pattern *list) struct glob_pattern *tmp = list; list = list->next; if (tmp->str) - free(tmp->str); - free(tmp); + GLOB_FREE(tmp->str); + GLOB_FREE(tmp); } } @@ -1246,7 +1247,7 @@ glob_helper( char *tmp = join_path(path, dirsep, ""); if (!tmp) return -1; status = glob_call_func(func, tmp, arg); - free(tmp); + GLOB_FREE(tmp); if (status) return status; } } @@ -1298,8 +1299,8 @@ glob_helper( } status = glob_helper(buf, 1, YES, new_isdir, new_beg, new_end, flags, func, arg); - free(buf); - free(new_beg); + GLOB_FREE(buf); + GLOB_FREE(new_beg); if (status) break; } @@ -1327,7 +1328,7 @@ glob_helper( new_beg = new_end = GLOB_ALLOC_N(struct glob_pattern *, end - beg); if (!new_beg) { - free(name); + GLOB_FREE(name); status = -1; break; } @@ -1340,20 +1341,20 @@ glob_helper( } buf = join_path(path, dirsep, name); - free(name); + GLOB_FREE(name); if (!buf) { - free(new_beg); + GLOB_FREE(new_beg); status = -1; break; } status = glob_helper(buf, 1, UNKNOWN, UNKNOWN, new_beg, new_end, flags, func, arg); - free(buf); - free(new_beg); + GLOB_FREE(buf); + GLOB_FREE(new_beg); if (status) break; } } - free(copy_beg); + GLOB_FREE(copy_beg); } return status; @@ -1384,12 +1385,12 @@ ruby_glob0(const char *path, int flags, ruby_glob_func *func, VALUE arg) list = glob_make_pattern(root, flags); if (!list) { - free(buf); + GLOB_FREE(buf); return -1; } status = glob_helper(buf, 0, UNKNOWN, UNKNOWN, &list, &list + 1, flags, func, arg); glob_free_pattern(list); - free(buf); + GLOB_FREE(buf); return status; } @@ -1486,7 +1487,7 @@ ruby_brace_expand(const char *str, int flags, ruby_glob_func *func, VALUE arg) status = ruby_brace_expand(buf, flags, func, arg); if (status) break; } - free(buf); + GLOB_FREE(buf); } else if (!lbrace && !rbrace) { status = (*func)(s, arg); -- cgit v1.2.3