From a05113a2b1aa196a135c9775ea87d85ef8f392ee Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Tue, 20 Nov 2012 10:28:35 +0100 Subject: [PATCH] unix-manager: memory handling fixes. This patch adds unlikey() for memory error handling and fixes a few error cases. --- src/unix-manager.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/unix-manager.c b/src/unix-manager.c index eee5c9093f..ec050e027f 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -109,7 +109,7 @@ int UnixNew(UnixCommand * this) if (ConfGet("unix-command.filename", &socketname) == 1) { int socketlen = strlen(SOCKET_PATH) + strlen(socketname) + 2; sockettarget = SCMalloc(socketlen); - if (sockettarget == NULL) { + if (unlikely(sockettarget == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate socket name"); return 0; } @@ -118,7 +118,7 @@ int UnixNew(UnixCommand * this) } if (sockettarget == NULL) { sockettarget = SCStrdup(SOCKET_TARGET); - if (sockettarget == NULL) { + if (unlikely(sockettarget == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate socket name"); return 0; } @@ -139,6 +139,7 @@ int UnixNew(UnixCommand * this) SCLogWarning(SC_ERR_OPENING_FILE, "Unix Socket: unable to create UNIX socket %s: %s", addr.sun_path, strerror(errno)); + SCFree(sockettarget); return 0; } this->select_max = this->socket + 1; @@ -336,7 +337,7 @@ int UnixCommandAccept(UnixCommand *this) SCLogInfo("Unix socket: client connected"); uclient = SCMalloc(sizeof(UnixClient)); - if (uclient == NULL) { + if (unlikely(uclient == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate new cient"); return 0; } @@ -641,11 +642,16 @@ TmEcode UnixManagerRegisterCommand(const char * keyword, } cmd = SCMalloc(sizeof(Command)); - if (cmd == NULL) { + if (unlikely(cmd == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Can't alloc cmd"); SCReturn(TM_ECODE_FAILED); } cmd->name = SCStrdup(keyword); + if (unlikely(cmd->name == NULL)) { + SCLogError(SC_ERR_MEM_ALLOC, "Can't alloc cmd name"); + SCFree(cmd); + SCReturn(TM_ECODE_FAILED); + } cmd->Func = Func; cmd->data = data; cmd->flags = flags; @@ -678,7 +684,7 @@ TmEcode UnixManagerRegisterBackgroundTask( } task = SCMalloc(sizeof(Task)); - if (task == NULL) { + if (unlikely(task == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Can't alloc task"); SCReturn(TM_ECODE_FAILED); }