From 6fd7a33b2a6f2b3a5696533676d2de4db2a87c47 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Thu, 30 Nov 2017 13:51:04 +0100 Subject: ipcpd: Don't read commands under lock The commands were read under a mutex. Since the cmd struct was just malloc'd, this is not needed. Also fixes closing the socket if the malloc fails. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/ipcp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index 44dbb52a..ba89e2cc 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -133,14 +133,12 @@ static void * acceptloop(void * o) cmd = malloc(sizeof(*cmd)); if (cmd == NULL) { log_err("Out of memory"); + close(csockfd); break; } - pthread_mutex_lock(&ipcpi.cmd_lock); - cmd->len = read(csockfd, cmd->cbuf, IPCP_MSG_BUF_SIZE); if (cmd->len <= 0) { - pthread_mutex_unlock(&ipcpi.cmd_lock); log_err("Failed to read from socket."); close(csockfd); free(cmd); @@ -149,6 +147,8 @@ static void * acceptloop(void * o) cmd->fd = csockfd; + pthread_mutex_lock(&ipcpi.cmd_lock); + list_add(&cmd->next, &ipcpi.cmds); pthread_cond_signal(&ipcpi.cmd_cond); -- cgit v1.2.3