]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util: THashInitConfig does not exit but return error
authorPhilippe Antoine <contact@catenacyber.fr>
Thu, 17 Sep 2020 08:18:39 +0000 (10:18 +0200)
committerJason Ish <jason.ish@oisf.net>
Wed, 7 Oct 2020 15:40:38 +0000 (09:40 -0600)
src/util-thash.c

index 6ba12b32cce7742be4a71d5f2fd5b17ea1b1b574..066e52b6e5625389fafff05fde70278fe4e19801 100644 (file)
@@ -204,7 +204,7 @@ static void THashDataFree(THashTableContext *ctx, THashData *h)
 
 /** \brief initialize the configuration
  *  \warning Not thread safe */
-static void THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
+static int THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
 {
     char varname[256];
 
@@ -222,7 +222,7 @@ static void THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
             SCLogError(SC_ERR_SIZE_PARSE, "Error parsing %s "
                        "from conf file - %s.  Killing engine",
                        varname, conf_val);
-            exit(EXIT_FAILURE);
+            return -1;
         }
     }
     GET_VAR(cnf_prefix, "hash-size");
@@ -254,12 +254,12 @@ static void THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
                 "total hash size by multiplying \"hash-size\" with %"PRIuMAX", "
                 "which is the hash bucket size.", ctx->config.memcap, hash_size,
                 (uintmax_t)sizeof(THashHashRow));
-        exit(EXIT_FAILURE);
+        return -1;
     }
     ctx->array = SCMallocAligned(ctx->config.hash_size * sizeof(THashHashRow), CLS);
     if (unlikely(ctx->array == NULL)) {
-        FatalError(SC_ERR_FATAL,
-                   "Fatal error encountered in THashInitConfig. Exiting...");
+        SCLogError(SC_ERR_THASH_INIT, "Fatal error encountered in THashInitConfig. Exiting...");
+        return -1;
     }
     memset(ctx->array, 0, ctx->config.hash_size * sizeof(THashHashRow));
 
@@ -276,18 +276,18 @@ static void THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
                     "max thash memcap reached. Memcap %"PRIu64", "
                     "Memuse %"PRIu64".", ctx->config.memcap,
                     ((uint64_t)SC_ATOMIC_GET(ctx->memuse) + THASH_DATA_SIZE(ctx)));
-            exit(EXIT_FAILURE);
+            return -1;
         }
 
         THashData *h = THashDataAlloc(ctx);
         if (h == NULL) {
             SCLogError(SC_ERR_THASH_INIT, "preallocating data failed: %s", strerror(errno));
-            exit(EXIT_FAILURE);
+            return -1;
         }
         THashDataEnqueue(&ctx->spare_q,h);
     }
 
-    return;
+    return 0;
 }
 
 THashTableContext *THashInit(const char *cnf_prefix, size_t data_size,
@@ -320,7 +320,10 @@ THashTableContext *THashInit(const char *cnf_prefix, size_t data_size,
     SC_ATOMIC_INIT(ctx->prune_idx);
     THashDataQueueInit(&ctx->spare_q);
 
-    THashInitConfig(ctx, cnf_prefix);
+    if (THashInitConfig(ctx, cnf_prefix) < 0) {
+        THashShutdown(ctx);
+        ctx = NULL;
+    }
     return ctx;
 }