summaryrefslogtreecommitdiff
path: root/src/ipcpd/ipcp.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-04 12:53:28 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-04 17:17:49 +0200
commit139001b60b32e756e947d6e3a55767be9063029d (patch)
tree45a23543682a69151622cda6100eb1656c64c773 /src/ipcpd/ipcp.c
parentc9cffcf863b23e75ccb6d7800ac0d48fd1612259 (diff)
downloadouroboros-139001b60b32e756e947d6e3a55767be9063029d.tar.gz
ouroboros-139001b60b32e756e947d6e3a55767be9063029d.zip
ipcpd: Fix memory leaks
ipcp-data was not correctly destroyed.
Diffstat (limited to 'src/ipcpd/ipcp.c')
-rw-r--r--src/ipcpd/ipcp.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index 8fed60eb..6b76f20e 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -91,6 +91,11 @@ static void close_ptr(void * o)
close(*((int *) o));
}
+static void clean_msg (void * msg)
+{
+ ipcp_msg__free_unpacked(msg, NULL);
+}
+
void * ipcp_main_loop(void * o)
{
int lsockfd;
@@ -123,11 +128,10 @@ void * ipcp_main_loop(void * o)
return (void *) 1;
}
- pthread_cleanup_push(close_ptr,
- (void *) &sockfd);
-
free(sock_path);
+ pthread_cleanup_push(close_ptr, (void *) &sockfd);
+
while (true) {
ret_msg.code = IPCP_MSG_CODE__IPCP_REPLY;
@@ -150,6 +154,8 @@ void * ipcp_main_loop(void * o)
continue;
}
+ pthread_cleanup_push(clean_msg, (void *) msg);
+
switch (msg->code) {
case IPCP_MSG_CODE__IPCP_BOOTSTRAP:
if (_ipcp->ops->ipcp_bootstrap == NULL) {
@@ -175,9 +181,8 @@ void * ipcp_main_loop(void * o)
conf.dns_addr = conf_msg->dns_addr;
}
- if (conf_msg->ipcp_type == IPCP_SHIM_ETH_LLC) {
+ if (conf_msg->ipcp_type == IPCP_SHIM_ETH_LLC)
conf.if_name = conf_msg->if_name;
- }
ret_msg.has_result = true;
ret_msg.result = _ipcp->ops->ipcp_bootstrap(&conf);
@@ -198,7 +203,8 @@ void * ipcp_main_loop(void * o)
break;
}
ret_msg.has_result = true;
- ret_msg.result = _ipcp->ops->ipcp_name_reg(msg->name);
+ ret_msg.result =
+ _ipcp->ops->ipcp_name_reg(strdup(msg->name));
break;
case IPCP_MSG_CODE__IPCP_NAME_UNREG:
if (_ipcp->ops->ipcp_name_unreg == NULL) {
@@ -206,7 +212,8 @@ void * ipcp_main_loop(void * o)
break;
}
ret_msg.has_result = true;
- ret_msg.result = _ipcp->ops->ipcp_name_unreg(msg->name);
+ ret_msg.result =
+ _ipcp->ops->ipcp_name_unreg(msg->name);
break;
case IPCP_MSG_CODE__IPCP_FLOW_ALLOC:
if (_ipcp->ops->ipcp_flow_alloc == NULL) {
@@ -246,7 +253,8 @@ void * ipcp_main_loop(void * o)
break;
}
- ipcp_msg__free_unpacked(msg, NULL);
+ pthread_cleanup_pop(true);
+
buffer.len = ipcp_msg__get_packed_size(&ret_msg);
if (buffer.len == 0) {
@@ -270,10 +278,10 @@ void * ipcp_main_loop(void * o)
}
free(buffer.data);
- close(lsockfd);
+
}
- pthread_cleanup_pop(false);
+ pthread_cleanup_pop(true);
return NULL;
}