diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-02 04:14:42 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-02 04:14:42 +0000 |
commit | 6bbd9104cbd1e1229a5c61a5e4498dc9b1a03239 (patch) | |
tree | 068eeb3a467a440af750a9c1b71d809d60ca2dd7 /win32/win32.c | |
parent | 71f2c19a9c65d154b8651218ae260fc4a8152cc2 (diff) | |
download | ruby-6bbd9104cbd1e1229a5c61a5e4498dc9b1a03239.tar.gz |
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/win32.c')
-rw-r--r-- | win32/win32.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/win32/win32.c b/win32/win32.c index 18ef8cb6d8..dfdd1e1c32 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -4813,27 +4813,23 @@ rb_w32_read_reparse_point(const WCHAR *path, rb_w32_reparse_buffer_t *rp, static ssize_t w32_readlink(UINT cp, const char *path, char *buf, size_t bufsize) { - WCHAR *wpath, *wname; VALUE wtmp; - size_t size = rb_w32_reparse_buffer_size(bufsize); - rb_w32_reparse_buffer_t *rp = ALLOCV(wtmp, size); - DWORD len; + DWORD len = MultiByteToWideChar(cp, 0, path, -1, NULL, 0); + size_t size = rb_w32_reparse_buffer_size(len); + WCHAR *wname, *wpath = ALLOCV(wtmp, size + sizeof(WCHAR) * len); + rb_w32_reparse_buffer_t *rp = (void *)(wpath + len); ssize_t ret; int e; - wpath = mbstr_to_wstr(cp, path, -1, NULL); - if (!wpath) { - ALLOCV_END(wtmp); - return -1; - } + MultiByteToWideChar(cp, 0, path, -1, wpath, len); e = rb_w32_read_reparse_point(wpath, rp, size, &wname, &len); - free(wpath); if (e && e != ERROR_MORE_DATA) { ALLOCV_END(wtmp); errno = map_errno(e); return -1; } ret = WideCharToMultiByte(cp, 0, wname, len, buf, bufsize, NULL, NULL); + ALLOCV_END(wtmp); if (e) { ret = bufsize; } |