diff options
author | dimitri staessens <[email protected]> | 2016-10-30 22:33:17 +0100 |
---|---|---|
committer | dimitri staessens <[email protected]> | 2016-10-31 07:54:59 +0100 |
commit | 4fb81107bfad2fe4cbea00cb87e1b6fbb92bd869 (patch) | |
tree | fbe9e6a85b9165334744647a3d7fd17b2459cbee /src/ipcpd/local/main.c | |
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/local/main.c')
-rw-r--r-- | src/ipcpd/local/main.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 412795ec..643d088d 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -140,7 +140,11 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c) 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); } @@ -154,9 +158,6 @@ static int ipcp_local_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); - pthread_rwlock_wrlock(&ipcpi.state_lock); if (ipcp_get_state() != IPCP_INIT) { @@ -165,6 +166,9 @@ static int ipcp_local_bootstrap(struct dif_config * conf) return -1; } + /* this IPCP doesn't need to maintain its dif_name */ + free(conf->dif_name); + ipcp_set_state(IPCP_ENROLLED); pthread_create(&local_data.sduloop, NULL, ipcp_local_sdu_loop, NULL); @@ -382,8 +386,10 @@ int main(int argc, char * argv[]) ipcp_fini(); - pthread_cancel(local_data.sduloop); - pthread_join(local_data.sduloop, NULL); + if (ipcp_get_state() == IPCP_SHUTDOWN) { + pthread_cancel(local_data.sduloop); + pthread_join(local_data.sduloop, NULL); + } local_data_fini(); |