]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mpm: cleanup pattern free function
authorVictor Julien <vjulien@oisf.net>
Mon, 27 Nov 2023 08:52:15 +0000 (09:52 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 1 Dec 2023 13:55:41 +0000 (14:55 +0100)
Avoid redundant pointer checks; instead check once.

src/util-mpm.c

index 47a19b2c8e88bbc5e209019d638f0ad35f0ddf11..0ccb78897c0935bb07f0ddff75ac38cbbe9127bb 100644 (file)
@@ -356,30 +356,30 @@ static inline MpmPattern *MpmAllocPattern(MpmCtx *mpm_ctx)
  */
 void MpmFreePattern(MpmCtx *mpm_ctx, MpmPattern *p)
 {
-    if (p != NULL && p->cs != NULL && p->cs != p->ci) {
+    if (p == NULL)
+        return;
+
+    if (p->cs != NULL && p->cs != p->ci) {
         SCFree(p->cs);
         mpm_ctx->memory_cnt--;
         mpm_ctx->memory_size -= p->len;
     }
 
-    if (p != NULL && p->ci != NULL) {
+    if (p->ci != NULL) {
         SCFree(p->ci);
         mpm_ctx->memory_cnt--;
         mpm_ctx->memory_size -= p->len;
     }
 
-    if (p != NULL && p->original_pat != NULL) {
+    if (p->original_pat != NULL) {
         SCFree(p->original_pat);
         mpm_ctx->memory_cnt--;
         mpm_ctx->memory_size -= p->len;
     }
 
-    if (p != NULL) {
-        SCFree(p);
-        mpm_ctx->memory_cnt--;
-        mpm_ctx->memory_size -= sizeof(MpmPattern);
-    }
-    return;
+    SCFree(p);
+    mpm_ctx->memory_cnt--;
+    mpm_ctx->memory_size -= sizeof(MpmPattern);
 }
 
 static inline uint32_t MpmInitHash(MpmPattern *p)