summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-12 14:55:22 +0000
committerocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-12 14:55:22 +0000
commita22893d663d7e822bcd05e75e7cb41667a9d77a5 (patch)
tree1c8c51148dbba24fea6cd1ff87ed9e1ed862a55d /util.c
parent82c050eab867bb4c6e04d68c683257124a50f405 (diff)
* 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/branches/ruby_1_8@6886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r--util.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/util.c b/util.c
index c294339..6f76519 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