summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-02-21 15:58:29 +0100
committerdimitri staessens <dimitri.staessens@ugent.be>2017-02-21 15:58:29 +0100
commit2a73f2d58cd29c6ecaade828db6ce1f5dde18a0e (patch)
treeccfccdbf0cb9dfd3db0f754660205eeb3a9eac7a /src/lib
parent198e319d14af53891b81cca36fe92e06d5d7d67d (diff)
downloadouroboros-2a73f2d58cd29c6ecaade828db6ce1f5dde18a0e.tar.gz
ouroboros-2a73f2d58cd29c6ecaade828db6ce1f5dde18a0e.zip
lib: Clean up memory management in cacep policies
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pol/cacep_anonymous_auth.c11
-rw-r--r--src/lib/pol/cacep_simple_auth.c8
2 files changed, 15 insertions, 4 deletions
diff --git a/src/lib/pol/cacep_anonymous_auth.c b/src/lib/pol/cacep_anonymous_auth.c
index 1ad8a533..1fcc730a 100644
--- a/src/lib/pol/cacep_anonymous_auth.c
+++ b/src/lib/pol/cacep_anonymous_auth.c
@@ -52,6 +52,8 @@ static struct cacep_info * anonymous_info(void)
if (info == NULL)
return NULL;
+ cacep_info_init(info);
+
info->name = malloc(NAME_LEN + 1);
if (info->name == NULL) {
free(info);
@@ -151,6 +153,8 @@ struct cacep_info * cacep_anonymous_auth(int fd,
{
struct cacep_info * tmp;
+ assert(info);
+
if (send_msg(fd, info))
return NULL;
@@ -161,6 +165,7 @@ struct cacep_info * cacep_anonymous_auth(int fd,
if (strcmp(info->proto.protocol, tmp->proto.protocol) ||
info->proto.pref_version != tmp->proto.pref_version ||
info->proto.pref_syntax != tmp->proto.pref_syntax) {
+ cacep_info_fini(tmp);
free(tmp);
return NULL;
}
@@ -176,11 +181,14 @@ struct cacep_info * cacep_anonymous_auth_wait(int fd,
{
struct cacep_info * tmp;
+ assert(info);
+
tmp = read_msg(fd);
if (tmp == NULL)
return NULL;
if (send_msg(fd, info)) {
+ cacep_info_fini(tmp);
free(tmp);
return NULL;
}
@@ -188,11 +196,10 @@ struct cacep_info * cacep_anonymous_auth_wait(int fd,
if (strcmp(info->proto.protocol, tmp->proto.protocol) ||
info->proto.pref_version != tmp->proto.pref_version ||
info->proto.pref_syntax != tmp->proto.pref_syntax) {
+ cacep_info_fini(tmp);
free(tmp);
return NULL;
}
- tmp->data = NULL;
-
return tmp;
}
diff --git a/src/lib/pol/cacep_simple_auth.c b/src/lib/pol/cacep_simple_auth.c
index b24a818b..65c510a2 100644
--- a/src/lib/pol/cacep_simple_auth.c
+++ b/src/lib/pol/cacep_simple_auth.c
@@ -59,6 +59,8 @@ static struct cacep_info * read_msg(int fd)
return NULL;
}
+ cacep_info_init(tmp);
+
tmp->addr = msg->addr;
tmp->name = strdup(msg->name);
if (tmp->name == NULL) {
@@ -78,8 +80,7 @@ static struct cacep_info * read_msg(int fd)
tmp->proto.pref_version = msg->proto->pref_version;
tmp->proto.pref_syntax = code_to_syntax(msg->proto->pref_syntax);
if (tmp->proto.pref_syntax < 0) {
- free(tmp->proto.protocol);
- free(tmp->name);
+ cacep_info_fini(tmp);
free(tmp);
cacep_simple_auth_msg__free_unpacked(msg, NULL);
return NULL;
@@ -144,6 +145,7 @@ struct cacep_info * cacep_simple_auth_auth(int fd,
if (strcmp(info->proto.protocol, tmp->proto.protocol) ||
info->proto.pref_version != tmp->proto.pref_version ||
info->proto.pref_syntax != tmp->proto.pref_syntax) {
+ cacep_info_fini(tmp);
free(tmp);
return NULL;
}
@@ -164,6 +166,7 @@ struct cacep_info * cacep_simple_auth_auth_wait(int fd,
return NULL;
if (send_msg(fd, info)) {
+ cacep_info_fini(tmp);
free(tmp);
return NULL;
}
@@ -171,6 +174,7 @@ struct cacep_info * cacep_simple_auth_auth_wait(int fd,
if (strcmp(info->proto.protocol, tmp->proto.protocol) ||
info->proto.pref_version != tmp->proto.pref_version ||
info->proto.pref_syntax != tmp->proto.pref_syntax) {
+ cacep_info_fini(tmp);
free(tmp);
return NULL;
}