Skip to content

Commit d1a5635

Browse files
committed
Uniform interface to truffleposix_get_user_home - always allocate
1 parent e3a2ffc commit d1a5635

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/main/c/truffleposix/truffleposix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ char* truffleposix_get_user_home(const char *name) {
202202
return NULL;
203203
} else {
204204
/* ret == 0 && result == NULL means not found */
205-
return "";
205+
return strdup("");
206206
}
207207
}
208208

src/main/ruby/core/file.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,8 @@ def self.expand_path(path, dir=nil)
497497

498498
if ptr = Truffle::POSIX.truffleposix_get_user_home(name)
499499
dir = ptr.read_string
500-
if dir.empty?
501-
raise ArgumentError, "user #{name} does not exist"
502-
else
503-
Truffle.invoke_primitive :pointer_free, ptr
504-
end
500+
Truffle.invoke_primitive :pointer_free, ptr
501+
raise ArgumentError, "user #{name} does not exist" if dir.empty?
505502
else
506503
Errno.handle
507504
end

0 commit comments

Comments
 (0)