From 9ffbc1eef916a775bdd86095a8b5a68608db6640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sun, 12 May 2024 18:33:00 +0200 Subject: [PATCH] osdep/io: fix leak of environment strings on win32 --- osdep/io.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/osdep/io.c b/osdep/io.c index a58eb6ec04..1e8171de59 100644 --- a/osdep/io.c +++ b/osdep/io.c @@ -664,11 +664,12 @@ static void free_env(void) static void init_getenv(void) { #if !HAVE_UWP - wchar_t *wenv = GetEnvironmentStringsW(); - if (!wenv) + wchar_t *wenv_begin = GetEnvironmentStringsW(); + if (!wenv_begin) return; utf8_environ_ctx = talloc_new(NULL); int num_env = 0; + wchar_t *wenv = wenv_begin; while (1) { size_t len = wcslen(wenv); if (!len) @@ -677,6 +678,7 @@ static void init_getenv(void) MP_TARRAY_APPEND(utf8_environ_ctx, utf8_environ, num_env, s); wenv += len + 1; } + FreeEnvironmentStringsW(wenv_begin); MP_TARRAY_APPEND(utf8_environ_ctx, utf8_environ, num_env, NULL); // Avoid showing up in leak detectors etc. atexit(free_env);