From 780b40ea7ba5773a41109108276e1eed207818c8 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Mon, 27 Feb 2023 11:58:12 -0700 Subject: [PATCH] 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. --- src/win/util.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/win/util.c b/src/win/util.c index 647d6e66..6232ce15 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -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. */