From 45a8dd4ccb3874c411dac287cf7ce862f051aa14 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sun, 29 Jan 2017 17:20:09 +0100 Subject: irmd: Fix memleak attempting double bootstrap When trying to double bootstrap, the entry name was strdup'd before the bootstrap leaking the previous name. Now it bootstraps first and sets the name after a successful bootstrap only. --- src/irmd/main.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/irmd/main.c b/src/irmd/main.c index 435ee116..02ffb21b 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -392,21 +392,19 @@ static int bootstrap_ipcp(pid_t api, dif_config_msg_t * conf) return -1; } - entry->dif_name = strdup(conf->dif_name); - if (entry->dif_name == NULL) { + if (ipcp_bootstrap(entry->api, conf)) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Failed to strdup."); + LOG_ERR("Could not bootstrap IPCP."); return -1; } - if (ipcp_bootstrap(entry->api, conf)) { + entry->dif_name = strdup(conf->dif_name); + if (entry->dif_name == NULL) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Could not bootstrap IPCP."); - free(entry->dif_name); - entry->dif_name = NULL; - return -1; + LOG_WARN("Failed to set name of DIF."); + return -ENOMEM; } pthread_rwlock_unlock(&irmd->reg_lock); -- cgit v1.2.3