summaryrefslogtreecommitdiff
path: root/src/ipcpd/shim-udp/main.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-10-25 21:22:25 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-10-25 21:26:30 +0200
commitd2ae65cff6a732ef6ad38a74380f27e36d464321 (patch)
tree3269a1d9b5a2d161f3e514bdd00f92453f417f40 /src/ipcpd/shim-udp/main.c
parentf689fd95ec35050f4c6bd89bedf21875a3438987 (diff)
downloadouroboros-d2ae65cff6a732ef6ad38a74380f27e36d464321.tar.gz
ouroboros-d2ae65cff6a732ef6ad38a74380f27e36d464321.zip
ipcpd: Fix memory leaks
Fixes memory leaks associated with the dif_name (which doesn't need to be maintained in shim DIFs) and the fqueue for the N + 1 flows.
Diffstat (limited to 'src/ipcpd/shim-udp/main.c')
-rw-r--r--src/ipcpd/shim-udp/main.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index 62e1b2d0..5abe0050 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -79,6 +79,7 @@ struct {
int s_fd;
flow_set_t * np1_flows;
+ fqueue_t * fq;
fd_set flow_fd_s;
/* bidir mappings of (n - 1) file descriptor to (n) flow descriptor */
int uf_to_fd[FD_SETSIZE];
@@ -112,6 +113,12 @@ static int udp_data_init(void)
if (udp_data.np1_flows == NULL)
return -ENOMEM;
+ udp_data.fq = fqueue_create();
+ if (udp_data.fq == NULL) {
+ flow_set_destroy(udp_data.np1_flows);
+ return -ENOMEM;
+ }
+
pthread_rwlock_init(&udp_data.flows_lock, NULL);
pthread_cond_init(&udp_data.fd_set_cond, NULL);
pthread_mutex_init(&udp_data.fd_set_lock, NULL);
@@ -122,6 +129,7 @@ static int udp_data_init(void)
static void udp_data_fini(void)
{
flow_set_destroy(udp_data.np1_flows);
+ fqueue_destroy(udp_data.fq);
pthread_rwlock_destroy(&udp_data.flows_lock);
pthread_mutex_destroy(&udp_data.fd_set_lock);
@@ -523,23 +531,16 @@ static void * ipcp_udp_sdu_loop(void * o)
int fd;
struct timespec timeout = {0, FD_UPDATE_TIMEOUT * 1000};
struct shm_du_buff * sdb;
- fqueue_t * fq = fqueue_create();
- if (fq == NULL)
- return (void *) 1;
(void) o;
while (true) {
- int ret = flow_event_wait(udp_data.np1_flows, fq, &timeout);
- if (ret == -ETIMEDOUT)
- continue;
-
- if (ret < 0) {
- LOG_ERR("Event wait returned error code %d.", -ret);
+ if (flow_event_wait(udp_data.np1_flows,
+ udp_data.fq,
+ &timeout) == -ETIMEDOUT)
continue;
- }
- while ((fd = fqueue_next(fq)) >= 0) {
+ while ((fd = fqueue_next(udp_data.fq)) >= 0) {
if (ipcp_flow_read(fd, &sdb)) {
LOG_ERR("Bad read from fd %d.", fd);
continue;
@@ -594,13 +595,11 @@ static int ipcp_udp_bootstrap(struct dif_config * conf)
int enable = 1;
int fd = -1;
- if (conf == NULL)
- return -1; /* -EINVAL */
+ assert(conf);
+ assert(conf->type == THIS_TYPE);
- if (conf->type != THIS_TYPE) {
- LOG_ERR("Config doesn't match IPCP type.");
- return -1;
- }
+ /* this IPCP doesn't need to maintain its dif_name */
+ free(conf->dif_name);
if (inet_ntop(AF_INET,
&conf->ip_addr,