]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util-logopenfile: don't allocate redis command
authorEric Leblond <eric@regit.org>
Wed, 14 Oct 2015 14:40:44 +0000 (16:40 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 22 Oct 2015 08:01:06 +0000 (10:01 +0200)
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
src/util-logopenfile.h

index cce748e84a307d5e086815d11eb3b6460bf247e2..c91e039c32dd2ae34f013179e993fe42d51c74b1 100644 (file)
@@ -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);
     }
index 06175b2b090f12f6d367b1bd060fbd7eb0aeb76c..d2924503d78f3031ba5380640b94d4a3f4ed37ac 100644 (file)
@@ -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;