From a9f74eb95d4c0da15b93d943ccdf872a642ea368 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 8 Mar 2024 09:16:16 +0000 Subject: su: free all allocated memory Ensure memory is freed even on early exit. Saves 0-16 bytes. --- loginutils/suw32.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/loginutils/suw32.c b/loginutils/suw32.c index 89ccec220..edf42177b 100644 --- a/loginutils/suw32.c +++ b/loginutils/suw32.c @@ -37,6 +37,7 @@ enum { int suw32_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int suw32_main(int argc UNUSED_PARAM, char **argv) { + int ret = 0; unsigned opt; char *opt_command = NULL; SHELLEXECUTEINFO info; @@ -105,17 +106,14 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) /* info.lpDirectory = NULL; */ info.nShow = SW_SHOWNORMAL; - if (!INIT_PROC_ADDR(shell32.dll, ShellExecuteExA)) - return -1; - - if (!ShellExecuteExA(&info)) - return 1; + if (!INIT_PROC_ADDR(shell32.dll, ShellExecuteExA)) { + ret = -1; + goto end; + } - if (ENABLE_FEATURE_CLEAN_UP) { - free(bb_path); - free(cwd); - free(realcwd); - free(args); + if (!ShellExecuteExA(&info)) { + ret = 1; + goto end; } if (opt & OPT_W) { @@ -123,12 +121,18 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) WaitForSingleObject(info.hProcess, INFINITE); if (!GetExitCodeProcess(info.hProcess, &r)) - r = 1; + ret = 1; else - r = exit_code_to_posix(r); + ret = exit_code_to_posix(r); CloseHandle(info.hProcess); - return r; + } + end: + if (ENABLE_FEATURE_CLEAN_UP) { + free(bb_path); + free(cwd); + free(realcwd); + free(args); } - return 0; + return ret; } -- cgit v1.2.3-55-g6feb