diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-10-30 22:33:17 +0100 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-10-31 07:54:59 +0100 |
commit | 4fb81107bfad2fe4cbea00cb87e1b6fbb92bd869 (patch) | |
tree | fbe9e6a85b9165334744647a3d7fd17b2459cbee /src/ipcpd/shim-udp | |
parent | 05fa4879dd8c70156fd98eabed4634098b0feecb (diff) | |
download | ouroboros-4fb81107bfad2fe4cbea00cb87e1b6fbb92bd869.tar.gz ouroboros-4fb81107bfad2fe4cbea00cb87e1b6fbb92bd869.zip |
ipcpd: Clean shutdown when bootstrap fails
Fixes a double free (conf->dif_name) and the handling of non-created
threads when the bootstrap of an IPCP fails
Diffstat (limited to 'src/ipcpd/shim-udp')
-rw-r--r-- | src/ipcpd/shim-udp/main.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index c90b47a2..159176ea 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -519,7 +519,11 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c) if (info->si_pid == irmd_api) { pthread_rwlock_wrlock(&ipcpi.state_lock); - ipcp_set_state(IPCP_SHUTDOWN); + if (ipcp_get_state() == IPCP_INIT) + ipcp_set_state(IPCP_NULL); + + if (ipcp_get_state() == IPCP_ENROLLED) + ipcp_set_state(IPCP_SHUTDOWN); pthread_rwlock_unlock(&ipcpi.state_lock); } @@ -539,9 +543,6 @@ static int ipcp_udp_bootstrap(struct dif_config * conf) assert(conf); assert(conf->type == THIS_TYPE); - /* this IPCP doesn't need to maintain its dif_name */ - free(conf->dif_name); - if (inet_ntop(AF_INET, &conf->ip_addr, ipstr, @@ -624,6 +625,9 @@ static int ipcp_udp_bootstrap(struct dif_config * conf) pthread_rwlock_unlock(&ipcpi.state_lock); + /* this IPCP doesn't need to maintain its dif_name */ + free(conf->dif_name); + LOG_DBG("Bootstrapped shim IPCP over UDP with api %d.", getpid()); LOG_DBG("Bound to IP address %s.", ipstr); LOG_DBG("DNS server address is %s.", dnsstr); @@ -1197,13 +1201,15 @@ int main(int argc, char * argv[]) ipcp_fini(); - pthread_cancel(udp_data.handler); - pthread_cancel(udp_data.sdu_reader); - pthread_cancel(udp_data.sduloop); - pthread_join(udp_data.sduloop, NULL); - pthread_join(udp_data.handler, NULL); - pthread_join(udp_data.sdu_reader, NULL); + if (ipcp_get_state() == IPCP_SHUTDOWN) { + pthread_cancel(udp_data.handler); + pthread_cancel(udp_data.sdu_reader); + pthread_cancel(udp_data.sduloop); + pthread_join(udp_data.sduloop, NULL); + pthread_join(udp_data.handler, NULL); + pthread_join(udp_data.sdu_reader, NULL); + } udp_data_fini(); |