summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2010-06-24 05:00:50 +0200
committerDenys Vlasenko2010-06-24 05:00:50 +0200
commitdd8adde3866ac22bd510348b733bb29e1662ac6d (patch)
tree2408903bb476f50821ed5edbe5b13abafe4a5439
parentda75f4484469ca0122b80de69bf3b75a6be71efc (diff)
downloadbusybox-dd8adde3866ac22bd510348b733bb29e1662ac6d.zip
busybox-dd8adde3866ac22bd510348b733bb29e1662ac6d.tar.gz
*: introduce and use bb_unsetenv_and_free
function old new delta bb_unsetenv_and_free - 17 +17 tcpudpsvd_main 1819 1810 -9 safe_setenv 58 47 -11 udhcp_run_script 630 616 -14 make_device 1683 1663 -20 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/4 up/down: 17/-54) Total: -37 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/xfuncs_printf.c5
-rw-r--r--miscutils/crond.c3
-rw-r--r--networking/tcpudp.c3
-rw-r--r--networking/udhcp/dhcpc.c3
-rw-r--r--util-linux/mdev.c6
6 files changed, 11 insertions, 10 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 5e962fd..58719a8 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -408,6 +408,7 @@ void xchdir(const char *path) FAST_FUNC;
void xchroot(const char *path) FAST_FUNC;
void xsetenv(const char *key, const char *value) FAST_FUNC;
void bb_unsetenv(const char *key) FAST_FUNC;
+void bb_unsetenv_and_free(char *key) FAST_FUNC;
void xunlink(const char *pathname) FAST_FUNC;
void xstat(const char *pathname, struct stat *buf) FAST_FUNC;
int xopen(const char *pathname, int flags) FAST_FUNC;
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index 03aeaaa..f021493 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -323,6 +323,11 @@ void FAST_FUNC bb_unsetenv(const char *var)
free(tp);
}
+void FAST_FUNC bb_unsetenv_and_free(char *var)
+{
+ bb_unsetenv(var);
+ free(var);
+}
// Die with an error message if we can't set gid. (Because resource limits may
// limit this user to a given number of processes, and if that fills up the
diff --git a/miscutils/crond.c b/miscutils/crond.c
index f511592..4a3103c 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -264,8 +264,7 @@ static void safe_setenv(char **pvar_val, const char *var, const char *val)
char *var_val = *pvar_val;
if (var_val) {
- bb_unsetenv(var_val);
- free(var_val);
+ bb_unsetenv_and_free(var_val);
}
*pvar_val = xasprintf("%s=%s", var, val);
putenv(*pvar_val);
diff --git a/networking/tcpudp.c b/networking/tcpudp.c
index 42845df..b32fad6 100644
--- a/networking/tcpudp.c
+++ b/networking/tcpudp.c
@@ -85,8 +85,7 @@ static void undo_xsetenv(void)
char **pp = env_cur = &env_var[0];
while (*pp) {
char *var = *pp;
- bb_unsetenv(var);
- free(var);
+ bb_unsetenv_and_free(var);
*pp++ = NULL;
}
}
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index c2b21c6..de1b798 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -327,8 +327,7 @@ static void udhcp_run_script(struct dhcp_packet *packet, const char *name)
for (curr = envp; *curr; curr++) {
log2(" %s", *curr);
- bb_unsetenv(*curr);
- free(*curr);
+ bb_unsetenv_and_free(*curr);
}
free(envp);
}
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 2170756..b4042c0 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -374,10 +374,8 @@ static void make_device(char *path, int delete)
putenv(s1);
if (system(command) == -1)
bb_perror_msg("can't run '%s'", command);
- unsetenv("SUBSYSTEM");
- free(s1);
- unsetenv("MDEV");
- free(s);
+ bb_unsetenv_and_free(s1);
+ bb_unsetenv_and_free(s);
free(command);
}