From d7da08aadd3b9768296db3c8744f58dd5e9697e8 Mon Sep 17 00:00:00 2001 From: ocean Date: Sun, 12 Sep 2004 14:55:22 +0000 Subject: [PATCH] * util.c (ruby_strdup): remove unnecessary code. (xmalloc never returns NULL.) * util.c (ruby_getcwd): fix memory leak on failure. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ util.c | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d95ebbf94..726c81634d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun Sep 12 23:53:17 2004 Hirokazu Yamamoto + + * util.c (ruby_strdup): remove unnecessary code. (xmalloc never + returns NULL.) + + * util.c (ruby_getcwd): fix memory leak on failure. + Sun Sep 12 02:41:58 2004 Hidetoshi NAGAI * ext/tcltklib/tcltklib.c: add TclTkIp#allow_ruby_exit? and diff --git a/util.c b/util.c index 3fe94074e8..98aa4d94b5 100644 --- a/util.c +++ b/util.c @@ -629,7 +629,6 @@ ruby_strdup(str) int len = strlen(str) + 1; tmp = xmalloc(len); - if (tmp == NULL) return NULL; memcpy(tmp, str, len); return tmp; @@ -643,7 +642,10 @@ ruby_getcwd() char *buf = xmalloc(size); while (!getcwd(buf, size)) { - if (errno != ERANGE) rb_sys_fail("getcwd"); + if (errno != ERANGE) { + free(buf); + rb_sys_fail("getcwd"); + } size *= 2; buf = xrealloc(buf, size); } @@ -654,6 +656,7 @@ ruby_getcwd() char *buf = xmalloc(PATH_MAX+1); if (!getwd(buf)) { + free(buf); rb_sys_fail("getwd"); } #endif