Skip to content

Commit

Permalink
Fix memory leak in _realloc if size is zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed Nov 5, 2024
1 parent c6439cc commit 492ae95
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions native/cocos/editor-support/spine-wasm/wasmSpineExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void *WasmSpineExtension::_realloc(void *ptr, size_t size, const char *file, int
SP_UNUSED(file);
SP_UNUSED(line);
if (size == 0) {
// Need to free the old memory before returning nullptr, otherwise the old memory block will be leaked.
::free(ptr);
return nullptr;
}
return ::realloc(ptr, sizeof(uint8_t) * size);
Expand Down

0 comments on commit 492ae95

Please sign in to comment.