util: THashInitConfig does not exit but return error

pull/4941/head
Philippe Antoine 5 years ago committed by Jason Ish
parent 2b215a45e0
commit dcd5e4dec9

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

Loading…
Cancel
Save