From 77e60e3368e5a73e1f0855a228f6a07473c3e6ab Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 21 Apr 2023 10:59:19 +0200 Subject: [PATCH] mpm/hs: fix scan-build warning util-mpm-hs.c:340:20: warning: Potential leak of memory pointed to by 'p' [unix.Malloc] p->sids[0] = sid; ~~~~~~~~~~~^~~~~ 1 warning generated. Incorrect error handling could lead to a memory leak. (cherry picked from commit ec84ba1a3c981108af4613fa16d5f13cc19e1f1d) --- src/util-mpm-hs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util-mpm-hs.c b/src/util-mpm-hs.c index 9ad204456f..dcdb1a9300 100644 --- a/src/util-mpm-hs.c +++ b/src/util-mpm-hs.c @@ -230,7 +230,7 @@ static inline int SCHSInitHashAdd(SCHSCtx *ctx, SCHSPattern *p) uint32_t hash = SCHSInitHash(p); if (ctx->init_hash == NULL) { - return 0; + return -1; } if (ctx->init_hash[hash] == NULL) { @@ -308,7 +308,8 @@ static int SCHSAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, memcpy(p->original_pat, pat, patlen); /* put in the pattern hash */ - SCHSInitHashAdd(ctx, p); + if (SCHSInitHashAdd(ctx, p) != 0) + goto error; mpm_ctx->pattern_cnt++; -- 2.47.2