diff options
| author | Paul Donald | 2025-12-22 23:35:01 +0000 |
|---|---|---|
| committer | Álvaro Fernández Rojas | 2025-12-28 11:46:37 +0000 |
| commit | 2e6682bfcaffacee62eccfc03f92ab1304a3b268 (patch) | |
| tree | ecc81964a876aa82958d9c3e57b2aff5ed22991d | |
| parent | 610e4bddb8d70dd6688e05156428e14c6181ee1a (diff) | |
| download | odhcp6c-2e6682bfcaffacee62eccfc03f92ab1304a3b268.tar.gz | |
odhcp6c: do cleanup at exit
cleanup frees all state buffers, releases any auth token,
and closes the random FD to avoid lingering allocations
after exit.
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/odhcp6c/pull/145
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
| -rw-r--r-- | src/odhcp6c.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/odhcp6c.c b/src/odhcp6c.c index 72705ff..1966d27 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -51,6 +51,7 @@ static void sighandler(int signal); static int usage(void); +static void odhcp6c_cleanup(void); static uint8_t *state_data[_STATE_MAX] = {NULL}; static size_t state_len[_STATE_MAX] = {0}; @@ -67,6 +68,25 @@ static time_t last_update = 0; static char *ifname = NULL; struct config_dhcp *config_dhcp = NULL; +static void odhcp6c_cleanup(void) +{ + for (int i = 0; i < _STATE_MAX; ++i) { + free(state_data[i]); + state_data[i] = NULL; + state_len[i] = 0; + } + + if (config_dhcp && config_dhcp->auth_token) { + free(config_dhcp->auth_token); + config_dhcp->auth_token = NULL; + } + + if (urandom_fd >= 0) { + close(urandom_fd); + urandom_fd = -1; + } +} + void __iflog(int lvl, const char *fmt, ...) { va_list ap; @@ -206,6 +226,8 @@ int main(_o_unused int argc, char* const argv[]) config_dhcp = config_dhcp_get(); config_dhcp_reset(); + atexit(odhcp6c_cleanup); + while ((c = getopt(argc, argv, "SDN:V:P:FB:c:i:r:Ru:Ux:s:EkK:t:C:m:Lhedp:favl:")) != -1) { switch (c) { case 'S': |