*: introduce and use bb_unsetenv_and_free
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 24 Jun 2010 03:00:50 +0000 (05:00 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 24 Jun 2010 03:00:50 +0000 (05:00 +0200)
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>
include/libbb.h
libbb/xfuncs_printf.c
miscutils/crond.c
networking/tcpudp.c
networking/udhcp/dhcpc.c
util-linux/mdev.c

index 5e962fdb6f67557ce3c3b001ece0933fade25ffe..58719a85b3581cf3535b5c6d66fe1e5b6c70bbc0 100644 (file)
@@ -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;
index 03aeaaa380aaf0cf2656c6cbc303833381ecb3e2..f021493b1ec8a505b844ce46e7b9257da58fbb0e 100644 (file)
@@ -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
index f51159233400b9c40255bdbf6f8c300187346ad8..4a3103cb9762c393ace16bdf12cbb20d20a479a4 100644 (file)
@@ -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);
index 42845df0eec446e9b2608d1896510219b667e627..b32fad624a8a68d0268674f3c96eccfb16853823 100644 (file)
@@ -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;
        }
 }
index c2b21c69564b6ed3ede80d2d808b0c0e8e7dc9e7..de1b798449bea750e37054f1a41c29ab616744d7 100644 (file)
@@ -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);
 }
index 21707566031a2c91ea80308d7a6e64cd64f30ea5..b4042c07ecaeda7bbabc2a9ad5c4707d36a13caf 100644 (file)
@@ -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);
                        }