summaryrefslogtreecommitdiff
path: root/win32/file.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-02 04:14:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-02 04:14:42 +0000
commit6bbd9104cbd1e1229a5c61a5e4498dc9b1a03239 (patch)
tree068eeb3a467a440af750a9c1b71d809d60ca2dd7 /win32/file.c
parent71f2c19a9c65d154b8651218ae260fc4a8152cc2 (diff)
win32: use ALLOCV
* win32/file.c (rb_readlink): use ALLOCV to get rid potential memory leak by NoMemoryError in ALLOCV. * win32/win32.c (w32_readlink): allocate WCHAR path name and reparse buffer together. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51737 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/file.c')
-rw-r--r--win32/file.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/win32/file.c b/win32/file.c
index 5b5f8999351..e5da59646e7 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -663,7 +663,7 @@ VALUE
rb_readlink(VALUE path)
{
DWORD len;
- VALUE wtmp = 0, str;
+ VALUE wtmp = 0, wpathbuf, str;
rb_w32_reparse_buffer_t rbuf, *rp = &rbuf;
WCHAR *wpath, *wbuf;
rb_encoding *enc;
@@ -677,16 +677,17 @@ rb_readlink(VALUE path)
path = fix_string_encoding(path, enc);
cp = CP_UTF8;
}
- wpath = mbstr_to_wstr(cp, RSTRING_PTR(path),
- RSTRING_LEN(path)+rb_enc_mbminlen(enc), NULL);
- if (!wpath) rb_memerror();
+ len = MultiByteToWideChar(cp, 0, RSTRING_PTR(path), RSTRING_LEN(path), NULL, 0);
+ wpath = ALLOCV_N(WCHAR, wpathbuf, len+1);
+ MultiByteToWideChar(cp, 0, RSTRING_PTR(path), RSTRING_LEN(path), wpath, len);
+ wpath[len] = L'\0';
e = rb_w32_read_reparse_point(wpath, rp, sizeof(rbuf), &wbuf, &len);
if (e == ERROR_MORE_DATA) {
size_t size = rb_w32_reparse_buffer_size(len + 1);
rp = ALLOCV(wtmp, size);
e = rb_w32_read_reparse_point(wpath, rp, size, &wbuf, &len);
}
- free(wpath);
+ ALLOCV_END(wpathbuf);
if (e) {
ALLOCV_END(wtmp);
rb_syserr_fail_path(rb_w32_map_errno(e), path);