Merge pull request #57652 from timothyqiu/decompress-dynamic
[3.x] Fix `PoolByteArray.decompress_dynamic` return value and memleak
This commit is contained in:
commit
98133deb97
1 changed files with 4 additions and 4 deletions
|
@ -660,17 +660,17 @@ struct _VariantCall {
|
||||||
|
|
||||||
static void _call_PoolByteArray_decompress_dynamic(Variant &r_ret, Variant &p_self, const Variant **p_args) {
|
static void _call_PoolByteArray_decompress_dynamic(Variant &r_ret, Variant &p_self, const Variant **p_args) {
|
||||||
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
||||||
PoolByteArray *decompressed = memnew(PoolByteArray);
|
PoolByteArray decompressed;
|
||||||
int max_output_size = (int)(*p_args[0]);
|
int max_output_size = (int)(*p_args[0]);
|
||||||
Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]);
|
Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]);
|
||||||
|
|
||||||
decompressed->resize(1024);
|
decompressed.resize(1024);
|
||||||
int result = Compression::decompress_dynamic(decompressed, max_output_size, ba->read().ptr(), ba->size(), mode);
|
int result = Compression::decompress_dynamic(&decompressed, max_output_size, ba->read().ptr(), ba->size(), mode);
|
||||||
|
|
||||||
if (result == OK) {
|
if (result == OK) {
|
||||||
r_ret = decompressed;
|
r_ret = decompressed;
|
||||||
} else {
|
} else {
|
||||||
decompressed->resize(0);
|
decompressed.resize(0);
|
||||||
r_ret = decompressed;
|
r_ret = decompressed;
|
||||||
ERR_FAIL_MSG("Decompression failed.");
|
ERR_FAIL_MSG("Decompression failed.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue