aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-03-08 09:16:16 +0000
committerRon Yorston <rmy@pobox.com>2024-03-08 09:19:30 +0000
commita9f74eb95d4c0da15b93d943ccdf872a642ea368 (patch)
tree0ecf6b2217192098cfad500b86d89b2a8c60b0c4
parent3aef195c435771e43ccddb6226f8c98519e2b830 (diff)
downloadbusybox-w32-a9f74eb95d4c0da15b93d943ccdf872a642ea368.tar.gz
busybox-w32-a9f74eb95d4c0da15b93d943ccdf872a642ea368.tar.bz2
busybox-w32-a9f74eb95d4c0da15b93d943ccdf872a642ea368.zip
su: free all allocated memory
Ensure memory is freed even on early exit. Saves 0-16 bytes.
-rw-r--r--loginutils/suw32.c32
1 files 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 {
37int suw32_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 37int suw32_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
38int suw32_main(int argc UNUSED_PARAM, char **argv) 38int suw32_main(int argc UNUSED_PARAM, char **argv)
39{ 39{
40 int ret = 0;
40 unsigned opt; 41 unsigned opt;
41 char *opt_command = NULL; 42 char *opt_command = NULL;
42 SHELLEXECUTEINFO info; 43 SHELLEXECUTEINFO info;
@@ -105,17 +106,14 @@ int suw32_main(int argc UNUSED_PARAM, char **argv)
105 /* info.lpDirectory = NULL; */ 106 /* info.lpDirectory = NULL; */
106 info.nShow = SW_SHOWNORMAL; 107 info.nShow = SW_SHOWNORMAL;
107 108
108 if (!INIT_PROC_ADDR(shell32.dll, ShellExecuteExA)) 109 if (!INIT_PROC_ADDR(shell32.dll, ShellExecuteExA)) {
109 return -1; 110 ret = -1;
110 111 goto end;
111 if (!ShellExecuteExA(&info)) 112 }
112 return 1;
113 113
114 if (ENABLE_FEATURE_CLEAN_UP) { 114 if (!ShellExecuteExA(&info)) {
115 free(bb_path); 115 ret = 1;
116 free(cwd); 116 goto end;
117 free(realcwd);
118 free(args);
119 } 117 }
120 118
121 if (opt & OPT_W) { 119 if (opt & OPT_W) {
@@ -123,12 +121,18 @@ int suw32_main(int argc UNUSED_PARAM, char **argv)
123 121
124 WaitForSingleObject(info.hProcess, INFINITE); 122 WaitForSingleObject(info.hProcess, INFINITE);
125 if (!GetExitCodeProcess(info.hProcess, &r)) 123 if (!GetExitCodeProcess(info.hProcess, &r))
126 r = 1; 124 ret = 1;
127 else 125 else
128 r = exit_code_to_posix(r); 126 ret = exit_code_to_posix(r);
129 CloseHandle(info.hProcess); 127 CloseHandle(info.hProcess);
130 return r; 128 }
129 end:
130 if (ENABLE_FEATURE_CLEAN_UP) {
131 free(bb_path);
132 free(cwd);
133 free(realcwd);
134 free(args);
131 } 135 }
132 136
133 return 0; 137 return ret;
134} 138}