From de47cb0c5b137e4aa047baa6e0d0fd76f0be1efd Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Sat, 5 Feb 2022 15:14:23 +0800 Subject: [PATCH] Fix PoolByteArray.decompress_dynamic return value and memleak --- core/variant_call.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/variant_call.cpp b/core/variant_call.cpp index df853474ce0..395ebee5ccb 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -660,17 +660,17 @@ struct _VariantCall { static void _call_PoolByteArray_decompress_dynamic(Variant &r_ret, Variant &p_self, const Variant **p_args) { PoolByteArray *ba = reinterpret_cast(p_self._data._mem); - PoolByteArray *decompressed = memnew(PoolByteArray); + PoolByteArray decompressed; int max_output_size = (int)(*p_args[0]); Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]); - decompressed->resize(1024); - int result = Compression::decompress_dynamic(decompressed, max_output_size, ba->read().ptr(), ba->size(), mode); + decompressed.resize(1024); + int result = Compression::decompress_dynamic(&decompressed, max_output_size, ba->read().ptr(), ba->size(), mode); if (result == OK) { r_ret = decompressed; } else { - decompressed->resize(0); + decompressed.resize(0); r_ret = decompressed; ERR_FAIL_MSG("Decompression failed."); }