]> 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>
Thu, 1 Nov 2018 14:46:10 +0000 (15:46 +0100)
src/detect-engine-address.c

index 6bedb2eeee371e8ab19ccfb665c815fbb385acfe..b98032e9feb8b37337fcd7255640e4e6e7dcdcb4 100644 (file)
@@ -714,31 +714,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
@@ -746,15 +741,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);