diff options
author | Sander Vrijders <[email protected]> | 2017-02-04 09:12:47 +0000 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2017-02-04 09:12:47 +0000 |
commit | e3b1288354349edc53c7c3c9ebd3efe23a7df10d (patch) | |
tree | 3a47f2b2db895173a1e3605df3fbdc925b7b127b | |
parent | c677d8a88065e6bc8e071f3f03a440e4ed083abb (diff) | |
parent | a30e244407655d16429ef442ac23db43a548bf95 (diff) | |
download | ouroboros-e3b1288354349edc53c7c3c9ebd3efe23a7df10d.tar.gz ouroboros-e3b1288354349edc53c7c3c9ebd3efe23a7df10d.zip |
Merged in dstaesse/ouroboros/be-wip (pull request #359)
irmd: Fix memleak in registry
-rw-r--r-- | src/ipcpd/ipcp.c | 7 | ||||
-rw-r--r-- | src/ipcpd/local/main.c | 9 | ||||
-rw-r--r-- | src/ipcpd/normal/dir.c | 2 | ||||
-rw-r--r-- | src/ipcpd/shim-eth-llc/main.c | 9 | ||||
-rw-r--r-- | src/ipcpd/shim-udp/main.c | 10 | ||||
-rw-r--r-- | src/irmd/registry.c | 1 |
6 files changed, 27 insertions, 11 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index 2c3beed7..2115f7c1 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -49,8 +49,6 @@ static void * ipcp_main_loop(void * o) dif_config_msg_t * conf_msg; struct dif_config conf; - char * msg_name_dup; - struct timeval ltv = {(SOCKET_TIMEOUT / 1000), (SOCKET_TIMEOUT % 1000) * 1000}; @@ -154,12 +152,9 @@ static void * ipcp_main_loop(void * o) LOG_ERR("Ap_reg unsupported."); break; } - msg_name_dup = strdup(msg->name); ret_msg.has_result = true; ret_msg.result = - ipcpi.ops->ipcp_name_reg(msg_name_dup); - if (ret_msg.result < 0) - free(msg_name_dup); + ipcpi.ops->ipcp_name_reg(msg->name); break; case IPCP_MSG_CODE__IPCP_NAME_UNREG: if (ipcpi.ops->ipcp_name_unreg == NULL) { diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 73c22975..c2b22732 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -168,11 +168,18 @@ static int ipcp_local_bootstrap(struct dif_config * conf) static int ipcp_local_name_reg(char * name) { + char * name_dup = strdup(name); + if (name_dup == NULL) { + LOG_ERR("Failed to duplicate name."); + return -ENOMEM; + } + pthread_rwlock_rdlock(&ipcpi.state_lock); - if (ipcp_data_reg_add_entry(ipcpi.data, name)) { + if (ipcp_data_reg_add_entry(ipcpi.data, name_dup)) { pthread_rwlock_unlock(&ipcpi.state_lock); LOG_DBG("Failed to add %s to local registry.", name); + free(name_dup); return -1; } diff --git a/src/ipcpd/normal/dir.c b/src/ipcpd/normal/dir.c index d9d15f72..49283529 100644 --- a/src/ipcpd/normal/dir.c +++ b/src/ipcpd/normal/dir.c @@ -123,8 +123,6 @@ int dir_name_reg(char * name) LOG_DBG("Registered %s.", name); pathname_destroy(path); - free(name); - return 0; } diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c index c59a8054..bc0d8a27 100644 --- a/src/ipcpd/shim-eth-llc/main.c +++ b/src/ipcpd/shim-eth-llc/main.c @@ -865,11 +865,18 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) static int eth_llc_ipcp_name_reg(char * name) { + char * name_dup = strdup(name); + if (name_dup == NULL) { + LOG_ERR("Failed to duplicate name."); + return -ENOMEM; + } + pthread_rwlock_rdlock(&ipcpi.state_lock); - if (ipcp_data_reg_add_entry(ipcpi.data, name)) { + if (ipcp_data_reg_add_entry(ipcpi.data, name_dup)) { pthread_rwlock_unlock(&ipcpi.state_lock); LOG_ERR("Failed to add %s to local registry.", name); + free(name_dup); return -1; } diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index e9c15579..c2f86067 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -776,17 +776,25 @@ static int ipcp_udp_name_reg(char * name) uint32_t dns_addr; uint32_t ip_addr; #endif + char * name_dup; if (strlen(name) > 24) { LOG_ERR("DNS names cannot be longer than 24 chars."); return -1; } + name_dup = strdup(name); + if (name_dup == NULL) { + LOG_ERR("Failed to duplicate name."); + return -ENOMEM; + } + pthread_rwlock_rdlock(&ipcpi.state_lock); - if (ipcp_data_reg_add_entry(ipcpi.data, name)) { + if (ipcp_data_reg_add_entry(ipcpi.data, name_dup)) { pthread_rwlock_unlock(&ipcpi.state_lock); LOG_ERR("Failed to add %s to local registry.", name); + free(name_dup); return -1; } diff --git a/src/irmd/registry.c b/src/irmd/registry.c index 35c17069..7e21375e 100644 --- a/src/irmd/registry.c +++ b/src/irmd/registry.c @@ -165,6 +165,7 @@ static void reg_entry_del_local_from_dif(struct reg_entry * e, struct reg_dif * d = list_entry(p, struct reg_dif, next); if (!strcmp(dif_name, d->dif_name)) { list_del(&d->next); + free(d->dif_name); free(d); } } |