From: Victor Julien Date: Mon, 27 Nov 2017 09:03:46 +0000 (+0100) Subject: http: allow shinking in HTPRealloc X-Git-Tag: suricata-4.0.2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f4a98955eb1ac205a86c62f74d1036e857b7f42;p=thirdparty%2Fsuricata.git http: allow shinking in HTPRealloc --- diff --git a/src/app-layer-htp-mem.c b/src/app-layer-htp-mem.c index 06bbe00f00..37ac6db1c5 100644 --- a/src/app-layer-htp-mem.c +++ b/src/app-layer-htp-mem.c @@ -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; }