win: fix leak in uv_chdir (#3912)

The call to uv__cwd() always returns a new allocation. The previously
allocated utf16_buffer needs to be free'd before passing it in to
receive the next allocation.
This commit is contained in:
Trevor Norris 2023-02-27 11:58:12 -07:00 committed by GitHub
parent e613fdd83c
commit 780b40ea7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -284,6 +284,10 @@ int uv_chdir(const char* dir) {
return uv_translate_sys_error(GetLastError());
}
/* uv__cwd() will return a new buffer. */
uv__free(utf16_buffer);
utf16_buffer = NULL;
/* Windows stores the drive-local path in an "hidden" environment variable,
* which has the form "=C:=C:\Windows". SetCurrentDirectory does not update
* this, so we'll have to do it. */