diff --git a/session.c b/session.c index a689b27ad..1e917c390 100644 --- a/session.c +++ b/session.c @@ -343,11 +343,7 @@ static void setup_session_user_vars(Session* s) /* set user environment variable ret = RegEnumValueW(reg_key, i++, name, &name_chars, 0, &type, (LPBYTE)data, &required); if (ret == ERROR_NO_MORE_ITEMS) break; - else if (ret != ERROR_SUCCESS) { - error("Error retrieving user environment variables. RegEnumValueW returned %d", ret); - break; - } - else if (required > data_chars * 2) { + else if (ret == ERROR_MORE_DATA || required > data_chars * 2) { if (data != NULL) free(data); data = xmalloc(required); @@ -355,6 +351,10 @@ static void setup_session_user_vars(Session* s) /* set user environment variable i--; continue; } + else if (ret != ERROR_SUCCESS) { + error("Error retrieving user environment variables. RegEnumValueW returned %d", ret); + break; + } if (type == REG_SZ) to_apply = data;