]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/address: minor memory handling cleanups
authorVictor Julien <victor@inliniac.net>
Thu, 25 Oct 2018 15:31:49 +0000 (17:31 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 30 Oct 2018 09:21:34 +0000 (10:21 +0100)
src/detect-engine-address.c

index a11e7f40d90b3dc6ecd4baf9a094626c26a58329..bfdd2e54fc093468a38b62eb930dba39e1d36ff2 100644 (file)
@@ -746,31 +746,26 @@ error:
  */
 static int DetectAddressSetup(DetectAddressHead *gh, const char *s)
 {
-    DetectAddress *ad = NULL;
-    DetectAddress *ad2 = NULL;
-    int r = 0;
-    char any = FALSE;
-
     SCLogDebug("gh %p, s %s", gh, s);
 
     /* parse the address */
-    ad = DetectAddressParseSingle(s);
+    DetectAddress *ad = DetectAddressParseSingle(s);
     if (ad == NULL) {
         SCLogError(SC_ERR_ADDRESS_ENGINE_GENERIC,
                 "failed to parse address \"%s\"", s);
         return -1;
     }
 
-    if (ad->flags & ADDRESS_FLAG_ANY)
-        any = TRUE;
+    char any = (ad->flags & ADDRESS_FLAG_ANY);
 
     /* handle the not case, we apply the negation then insert the part(s) */
     if (ad->flags & ADDRESS_FLAG_NOT) {
-        ad2 = NULL;
+        DetectAddress *ad2 = NULL;
 
         if (DetectAddressCutNot(ad, &ad2) < 0) {
             SCLogDebug("DetectAddressCutNot failed");
-            goto error;
+            DetectAddressFree(ad);
+            return -1;
         }
 
         /* normally a 'not' will result in two ad's unless the 'not' is on the start or end
@@ -778,15 +773,18 @@ static int DetectAddressSetup(DetectAddressHead *gh, const char *s)
         if (ad2 != NULL) {
             if (DetectAddressInsert(NULL, gh, ad2) < 0) {
                 SCLogDebug("DetectAddressInsert failed");
-                goto error;
+                DetectAddressFree(ad);
+                DetectAddressFree(ad2);
+                return -1;
             }
         }
     }
 
-    r = DetectAddressInsert(NULL, gh, ad);
+    int r = DetectAddressInsert(NULL, gh, ad);
     if (r < 0) {
         SCLogDebug("DetectAddressInsert failed");
-        goto error;
+        DetectAddressFree(ad);
+        return -1;
     }
     SCLogDebug("r %d",r);