From d88e1334283b37ee2c3d409d38632062d261c67e Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Wed, 14 Oct 2015 16:40:44 +0200 Subject: [PATCH] util-logopenfile: don't allocate redis command As we only have two different commands we don't need to allocate it and can use pointer to global variables. --- src/util-logopenfile.c | 9 +++++---- src/util-logopenfile.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/util-logopenfile.c b/src/util-logopenfile.c index cce748e84a..c91e039c32 100644 --- a/src/util-logopenfile.c +++ b/src/util-logopenfile.c @@ -34,6 +34,9 @@ #include "util-logopenfile.h" #include "util-logopenfile-tile.h" +const char * redis_push_cmd = "LPUSH"; +const char * redis_publish_cmd = "PUBLISH"; + /** \brief connect to the indicated local stream socket, logging any errors * \param path filesystem path to connect to * \param log_err, non-zero if connect failure should be logged. @@ -399,13 +402,13 @@ int SCConfLogOpenRedis(ConfNode *redis_node, LogFileCtx *log_ctx) } if (!strcmp(redis_mode, "list")) { - log_ctx->redis_setup.command = SCStrdup("LPUSH"); + log_ctx->redis_setup.command = redis_push_cmd; if (!log_ctx->redis_setup.command) { SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate redis key command"); exit(EXIT_FAILURE); } } else { - log_ctx->redis_setup.command = SCStrdup("PUBLISH"); + log_ctx->redis_setup.command = redis_publish_cmd; if (!log_ctx->redis_setup.command) { SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate redis key command"); exit(EXIT_FAILURE); @@ -509,8 +512,6 @@ int LogFileFreeCtx(LogFileCtx *lf_ctx) redisFree(lf_ctx->redis); if (lf_ctx->redis_setup.server) SCFree(lf_ctx->redis_setup.server); - if (lf_ctx->redis_setup.command) - SCFree(lf_ctx->redis_setup.command); if (lf_ctx->redis_setup.key) SCFree(lf_ctx->redis_setup.key); } diff --git a/src/util-logopenfile.h b/src/util-logopenfile.h index 06175b2b09..d2924503d7 100644 --- a/src/util-logopenfile.h +++ b/src/util-logopenfile.h @@ -51,7 +51,7 @@ enum RedisMode { REDIS_LIST, REDIS_CHANNEL }; typedef struct RedisSetup_ { enum RedisMode mode; - char *command; + const char *command; char *key; int batch_size; int batch_count;