From 49592833a7c507f06385a4b6b2ec343c05eaf8f8 Mon Sep 17 00:00:00 2001 From: "Wang, Xiang W" Date: Tue, 9 Jul 2019 20:18:42 -0400 Subject: [PATCH] Scratch: fix scratch free issue when memory allocation fails Fixes github issue #174 --- src/scratch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/scratch.c b/src/scratch.c index b4630640..25991e2b 100644 --- a/src/scratch.c +++ b/src/scratch.c @@ -279,7 +279,9 @@ hs_error_t HS_CDECL hs_alloc_scratch(const hs_database_t *db, hs_error_t proto_ret = hs_check_alloc(proto_tmp); if (proto_ret != HS_SUCCESS) { hs_scratch_free(proto_tmp); - hs_scratch_free(*scratch); + if (*scratch) { + hs_scratch_free((*scratch)->scratch_alloc); + } *scratch = NULL; return proto_ret; }