diff options
Diffstat (limited to 'src/ipcpd/ipcp.c')
-rw-r--r-- | src/ipcpd/ipcp.c | 28 |
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; } |