From 12c880a7783831fde3fbfdc1a3954e2b801bdb23 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 27 Nov 2017 10:03:46 +0100 Subject: [PATCH] http: allow shinking in HTPRealloc --- src/app-layer-htp-mem.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app-layer-htp-mem.c b/src/app-layer-htp-mem.c index c9caefa2df..743c926fad 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; }