From 0c7758a555522b5a0e3ebfda34ba24b466b75bef Mon Sep 17 00:00:00 2001 From: ziggurat29 <30310677+ziggurat29@users.noreply.github.com> Date: Tue, 12 Feb 2019 15:30:54 -0600 Subject: [PATCH] Fix occasional luac.cross crash (#2661) A block of memory is accessed after having been freed. This was obscured by the fact that 'oBuf' is a pointer into the middle of the block 'dynamicTables', so when dynamicTables is freed, oBuf is pointing to freed memory. Occasionally, luac.cross would crash because of this. --- app/uzlib/uzlib_deflate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/uzlib/uzlib_deflate.c b/app/uzlib/uzlib_deflate.c index f393da33..07534195 100644 --- a/app/uzlib/uzlib_deflate.c +++ b/app/uzlib/uzlib_deflate.c @@ -568,7 +568,6 @@ int uzlib_compress (uchar **dest, uint *destLen, const uchar *src, uint srcLen) status = UZLIB_OK; } - FREE(dynamicTables); for (i=0; i<20;i++) DBG_PRINT("count %u = %u\n",i,debugCounts[i]); if (status == UZLIB_OK) { @@ -581,5 +580,7 @@ int uzlib_compress (uchar **dest, uint *destLen, const uchar *src, uint srcLen) FREE(oBuf->buffer); } + FREE(dynamicTables); + return status; }