summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2017-11-30 13:51:04 +0100
committerSander Vrijders <sander.vrijders@ugent.be>2017-11-30 14:18:39 +0100
commit6fd7a33b2a6f2b3a5696533676d2de4db2a87c47 (patch)
treeacd7fd01b49b1e934c1a658ab3d3cc53dc2266ce
parenta3fa3d4fec3994597b9c745709b4b85887913308 (diff)
downloadouroboros-6fd7a33b2a6f2b3a5696533676d2de4db2a87c47.tar.gz
ouroboros-6fd7a33b2a6f2b3a5696533676d2de4db2a87c47.zip
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 <dimitri.staessens@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
-rw-r--r--src/ipcpd/ipcp.c6
1 files 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);