summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2017-11-30 16:01:32 +0100
committerSander Vrijders <[email protected]>2017-11-30 16:24:34 +0100
commitf43e5e2329fb798047d15dd0748e5eef3359c966 (patch)
treeaddd496074bfb6f8db204a84f320c1d30b1a747e /src
parent6fd7a33b2a6f2b3a5696533676d2de4db2a87c47 (diff)
downloadouroboros-f43e5e2329fb798047d15dd0748e5eef3359c966.tar.gz
ouroboros-f43e5e2329fb798047d15dd0748e5eef3359c966.zip
irmd: 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 <[email protected]> Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/irmd/main.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 4d511af9..f9438b9b 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -1840,14 +1840,12 @@ static void * acceptloop(void * o)
cmd = malloc(sizeof(*cmd));
if (cmd == NULL) {
log_err("Out of memory.");
+ close(csockfd);
break;
}
- pthread_mutex_lock(&irmd.cmd_lock);
-
cmd->len = read(csockfd, cmd->cbuf, IRM_MSG_BUF_SIZE);
if (cmd->len <= 0) {
- pthread_mutex_unlock(&irmd.cmd_lock);
log_err("Failed to read from socket.");
close(csockfd);
free(cmd);
@@ -1856,6 +1854,8 @@ static void * acceptloop(void * o)
cmd->fd = csockfd;
+ pthread_mutex_lock(&irmd.cmd_lock);
+
list_add(&cmd->next, &irmd.cmds);
pthread_cond_signal(&irmd.cmd_cond);