From d435df363ff8e2ac5303cb837c9ff2604920ae56 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 5 Nov 2011 23:26:11 -0700 Subject: * lib.c (env): Fixed inappropriate cut-and-pasted error messages. Check for failure of GetEnvironmentStringsW, and call FreeEnvironmentStringsW is called. --- ChangeLog | 6 ++++++ lib.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d4d6597e..bc176237 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-11-05 Kaz Kylheku + + * lib.c (env): Fixed inappropriate cut-and-pasted error messages. + Check for failure of GetEnvironmentStringsW, and call + FreeEnvironmentStringsW is called. + 2011-11-05 Kaz Kylheku * match.c (dir_tables_init): Bugfix: horizontal @(some) diff --git a/lib.c b/lib.c index 040f92f1..72cbd551 100644 --- a/lib.c +++ b/lib.c @@ -2319,13 +2319,19 @@ val env(void) return env_list = out; #elif HAVE_GETENVIRONMENTSTRINGS wchar_t *env = GetEnvironmentStringsW(); + wchar_t *iter = env; - for (; *env; env += wcslen(env) + 1) - list_collect (ptail, string(env)); + if (iter == 0) + uw_throwf(error_s, lit("out of memory"), nao); + + for (; *iter; iter += wcslen(iter) + 1) + list_collect (ptail, string(iter)); + + FreeEnvironmentStringsW(env); return env_list = out; #else - uw_throwf(error_s, lit("string_extend: overflow"), nao); + uw_throwf(error_s, lit("environment strings not available"), nao); #endif } } -- cgit v1.2.3