From: Philippe Antoine Date: Thu, 17 Sep 2020 08:18:39 +0000 (+0200) Subject: util: THashInitConfig does not exit but return error X-Git-Tag: suricata-6.0.0~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dcd5e4dec9a980402060e49458616ae5690cb635;p=thirdparty%2Fsuricata.git util: THashInitConfig does not exit but return error --- diff --git a/src/util-thash.c b/src/util-thash.c index 6ba12b32cc..066e52b6e5 100644 --- a/src/util-thash.c +++ b/src/util-thash.c @@ -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; }