summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2018-03-22 16:13:19 +0100
committerSander Vrijders <sander.vrijders@ugent.be>2018-03-22 16:29:06 +0100
commite78740a4da0feb678f22bbc22b4c14a1f9a7bf7f (patch)
tree80acdebc62a722dee1bf5a263b0f02c894bb3152 /src/irmd
parent751fb58bcf5fdb31c0627a5153684e96126cffb6 (diff)
downloadouroboros-e78740a4da0feb678f22bbc22b4c14a1f9a7bf7f.tar.gz
ouroboros-e78740a4da0feb678f22bbc22b4c14a1f9a7bf7f.zip
irmd: Fix memleak when failing to list ipcps
The list_ipcps call had a memleak in the failure case. Also fixes a compiler warning for a possible uninitialized variable and renumbers the gpb ipcpd message fields. Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/main.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index e90cbbc8..ad121f98 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -867,7 +867,6 @@ static ssize_t list_ipcps(ipcp_info_msg_t *** ipcps,
pthread_rwlock_rdlock(&irmd.reg_lock);
*n_ipcps = irmd.n_ipcps;
-
if (*n_ipcps == 0) {
pthread_rwlock_unlock(&irmd.reg_lock);
return 0;
@@ -883,18 +882,20 @@ static ssize_t list_ipcps(ipcp_info_msg_t *** ipcps,
list_for_each(p, &irmd.ipcps) {
struct ipcp_entry * e = list_entry(p, struct ipcp_entry, next);
(*ipcps)[i] = malloc(sizeof(***ipcps));
- if ((*ipcps)[i] == NULL)
- goto fail_malloc;
+ if ((*ipcps)[i] == NULL) {
+ --i;
+ goto fail;
+ }
ipcp_info_msg__init((*ipcps)[i]);
(*ipcps)[i]->name = strdup(e->name);
if ((*ipcps)[i]->name == NULL)
- goto fail_mem;
+ goto fail;
(*ipcps)[i]->layer = strdup(
e->layer != NULL ? e->layer : "Not enrolled");
if ((*ipcps)[i]->layer == NULL)
- goto fail_mem;
+ goto fail;
(*ipcps)[i]->pid = e->pid;
(*ipcps)[i++]->type = e->type;
@@ -904,22 +905,15 @@ static ssize_t list_ipcps(ipcp_info_msg_t *** ipcps,
return 0;
- fail_mem:
- while (i > 0) {
+ fail:
+ while (i >= 0) {
free((*ipcps)[i]->layer);
free((*ipcps)[i]->name);
- free(*ipcps[--i]);
+ free(*ipcps[i--]);
}
free(*ipcps);
*n_ipcps = 0;
return -ENOMEM;
-
- fail_malloc:
- while (i > 0)
- free(*ipcps[--i]);
- free(*ipcps);
- *n_ipcps = 0;
- return -ENOMEM;
}
static int irm_update_name(const char * name)