* HOME=pw->pw_dir
* SHELL=shell
* else does nothing
+ *
+ * NB: CHANGEENV and CLEARENV use setenv() - this leaks memory!
+ * If setup_environment() is used is vforked child, this leaks memory _in parent too_!
*/
#define SETUP_ENV_CHANGEENV (1 << 0)
#define SETUP_ENV_CLEARENV (1 << 1)
/* r < 0 - can't exec, 0 <= r < 0x180 - exited, >=0x180 - killed by sig (r-0x180) */
r = spawn_and_wait(argv);
- unsetenv(IFPLUGD_ENV_PREVIOUS);
- unsetenv(IFPLUGD_ENV_CURRENT);
- free(env_PREVIOUS);
- free(env_CURRENT);
+ bb_unsetenv_and_free(env_PREVIOUS);
+ bb_unsetenv_and_free(env_CURRENT);
bb_error_msg("exit code: %d", r & 0xff);
return (option_mask32 & FLAG_IGNORE_RETVAL) ? 0 : r;
int status;
const char *addr = addr; /* for gcc */
const char *fmt = "%s %s %s" + 3;
+ char *env_ip = env_ip;
argv[2] = (char*)param;
if (nip != 0) {
addr = nip_to_a(nip);
- xsetenv("ip", addr);
+ /* Must not use setenv() repeatedly, it leaks memory. Use putenv() */
+ env_ip = xasprintf("ip=%s", addr);
+ putenv(env_ip);
fmt -= 3;
}
bb_error_msg(fmt, argv[2], argv[0], addr);
-
status = spawn_and_wait(argv + 1);
+ if (nip != 0)
+ bb_unsetenv_and_free(env_ip);
+
if (status < 0) {
bb_perror_msg("%s %s %s" + 3, argv[2], argv[0]);
return -errno;