From 4de841c26b7208d5395da349ea16c937b1361414 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Tue, 29 Aug 2017 13:14:25 +0200 Subject: lib, ipcpd, irmd: Fix bugs reported by static analysis This fixes several bugs as reported by the clang static analyzer. --- src/irmd/main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/irmd/main.c') diff --git a/src/irmd/main.c b/src/irmd/main.c index cc15e092..09a76214 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -307,6 +307,7 @@ static pid_t create_ipcp(char * name, entry = get_ipcp_entry_by_name(name); if (entry != NULL) { pthread_rwlock_unlock(&irmd.reg_lock); + free(api); log_err("IPCP by that name already exists."); return -1; } @@ -314,6 +315,7 @@ static pid_t create_ipcp(char * name, api->pid = ipcp_create(name, ipcp_type); if (api->pid == -1) { pthread_rwlock_unlock(&irmd.reg_lock); + free(api); log_err("Failed to create IPCP."); return -1; } @@ -321,6 +323,7 @@ static pid_t create_ipcp(char * name, tmp = ipcp_entry_create(); if (tmp == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); + free(api); return -1; } @@ -330,6 +333,7 @@ static pid_t create_ipcp(char * name, if (tmp->name == NULL) { ipcp_entry_destroy(tmp); pthread_rwlock_unlock(&irmd.reg_lock); + free(api); return -1; } @@ -833,6 +837,11 @@ static ssize_t list_ipcps(char * name, count++; } + if (count == 0) { + pthread_rwlock_unlock(&irmd.reg_lock); + return 0; + } + *apis = malloc(count * sizeof(pid_t)); if (*apis == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); @@ -1039,10 +1048,12 @@ static int api_announce(pid_t api, pthread_rwlock_unlock(&irmd.reg_lock); return -ENOMEM; } + n->str = strdup(s->str); if (n->str == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); free(n); + return -ENOMEM; } list_add(&n->next, &e->names); -- cgit v1.2.3