summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@intec.ugent.be>2016-03-17 10:42:35 +0100
committerDimitri Staessens <dimitri.staessens@intec.ugent.be>2016-03-17 10:42:35 +0100
commit80679807f5ed13fd0a214bc6cd4e1c182d87bfae (patch)
tree1b13d3833029a2bdab59ad287fa44eb762f82994
parent788414c1a728440e25b8a7428af294189e3b70ca (diff)
parent7747528435d77ad055a5c3124a89717e42807b9a (diff)
downloadouroboros-80679807f5ed13fd0a214bc6cd4e1c182d87bfae.tar.gz
ouroboros-80679807f5ed13fd0a214bc6cd4e1c182d87bfae.zip
Merged in sandervrijders/ouroboros/be (pull request #34)
lib, irmd: Fix memleaks
-rw-r--r--include/ouroboros/sockets.h2
-rw-r--r--src/irmd/main.c13
-rw-r--r--src/lib/sockets.c1
3 files changed, 15 insertions, 1 deletions
diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h
index b34537a7..871e3c36 100644
--- a/include/ouroboros/sockets.h
+++ b/include/ouroboros/sockets.h
@@ -51,7 +51,9 @@ struct irm_msg {
int client_socket_open(char * file_name);
int server_socket_open(char * file_name);
+/* Caller has to free the buffer */
buffer_t * serialize_irm_msg(struct irm_msg * msg);
+/* Caller has to free all the allocated fields in the message */
struct irm_msg * deserialize_irm_msg(buffer_t * data);
#endif
diff --git a/src/irmd/main.c b/src/irmd/main.c
index b695519a..99896999 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -203,7 +203,7 @@ static void unreg_ipcp(struct irm * instance,
/* FIXME: Close sockfd on closing and release irm */
int main()
{
- struct irm * instance;
+ struct irm * instance = NULL;
int sockfd;
uint8_t buf[IRM_MSG_BUF_SIZE];
@@ -222,6 +222,7 @@ int main()
struct irm_msg * msg;
ssize_t count;
buffer_t buffer;
+ int i;
cli_sockfd = accept(sockfd, 0, 0);
if (cli_sockfd < 0) {
@@ -242,6 +243,7 @@ int main()
create_ipcp(instance,
*(msg->name),
msg->ipcp_type);
+ free(msg->ipcp_type);
break;
case IRM_DESTROY_IPCP:
destroy_ipcp(instance,
@@ -251,28 +253,37 @@ int main()
bootstrap_ipcp(instance,
*(msg->name),
*(msg->conf));
+ free(msg->conf);
break;
case IRM_ENROLL_IPCP:
enroll_ipcp(instance,
*(msg->name),
msg->dif_name);
+ free(msg->dif_name);
break;
case IRM_REG_IPCP:
reg_ipcp(instance,
*(msg->name),
msg->difs,
msg->difs_size);
+ for (i = 0; i < msg->difs_size; i++)
+ free(msg->difs[i]);
+ free(msg->difs);
break;
case IRM_UNREG_IPCP:
unreg_ipcp(instance,
*(msg->name),
msg->difs,
msg->difs_size);
+ for (i = 0; i < msg->difs_size; i++)
+ free(msg->difs[i]);
+ free(msg->difs);
break;
default:
LOG_ERR("Don't know that message code");
break;
}
+ name_destroy(msg->name);
free(msg);
}
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index 90117c5c..59ac40f9 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -338,6 +338,7 @@ struct irm_msg * deserialize_irm_msg(buffer_t * data)
case IRM_REG_IPCP:
case IRM_UNREG_IPCP:
deser_copy_size_t(data->data, &difs_size, &offset);
+ msg->difs_size = difs_size;
msg->difs = malloc(sizeof(*(msg->difs)) * difs_size);
if (msg->difs == NULL) {