]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mpm/hs: fix scan-build warning
authorVictor Julien <vjulien@oisf.net>
Fri, 21 Apr 2023 08:59:19 +0000 (10:59 +0200)
committerVictor Julien <vjulien@oisf.net>
Mon, 24 Apr 2023 05:17:22 +0000 (07:17 +0200)
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.

src/util-mpm-hs.c

index 65fda758e0f12493498609bd58896cedcdbc91fa..a6fb82372cf79030cd79a2fee2c78b1510e675b1 100644 (file)
@@ -231,7 +231,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) {
@@ -309,7 +309,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++;