]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http: allow shinking in HTPRealloc
authorVictor Julien <victor@inliniac.net>
Mon, 27 Nov 2017 09:03:46 +0000 (10:03 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 28 Nov 2017 11:54:54 +0000 (12:54 +0100)
src/app-layer-htp-mem.c

index 06bbe00f00cca24718e108d3fd8e7fe2356a09bf..37ac6db1c5099f4dd904903d11a625da18d734cb 100644 (file)
@@ -140,16 +140,20 @@ void *HTPCalloc(size_t n, size_t size)
 
 void *HTPRealloc(void *ptr, size_t orig_size, size_t size)
 {
-    void *rptr = NULL;
-
-    if (HTPCheckMemcap((uint32_t)(size - orig_size)) == 0)
-        return NULL;
+    if (size > orig_size) {
+        if (HTPCheckMemcap((uint32_t)(size - orig_size)) == 0)
+            return NULL;
+    }
 
-    rptr = SCRealloc(ptr, size);
+    void *rptr = SCRealloc(ptr, size);
     if (rptr == NULL)
         return NULL;
 
-    HTPIncrMemuse((uint64_t)(size - orig_size));
+    if (size > orig_size) {
+        HTPIncrMemuse((uint64_t)(size - orig_size));
+    } else {
+        HTPDecrMemuse((uint64_t)(orig_size - size));
+    }
 
     return rptr;
 }