From bac7888c08db3f01287d108a5f91148818cfaaaf Mon Sep 17 00:00:00 2001 From: Marc Gurevitx Date: Wed, 22 May 2024 09:30:55 +0300 Subject: [PATCH] Free data on RawData.resize(0) --- MiniScript-cpp/src/ShellIntrinsics.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MiniScript-cpp/src/ShellIntrinsics.cpp b/MiniScript-cpp/src/ShellIntrinsics.cpp index 7e2c133..ecf68e4 100644 --- a/MiniScript-cpp/src/ShellIntrinsics.cpp +++ b/MiniScript-cpp/src/ShellIntrinsics.cpp @@ -104,15 +104,16 @@ class RawDataHandleStorage : public RefCountedStorage { } virtual ~RawDataHandleStorage() { free(data); } void resize(size_t newSize) { - if (data) { + if (newSize == 0) { + free(data); + data = nullptr; + dataSize = 0; + } else { void *newData = realloc(data, newSize); if (newData) { data = newData; dataSize = newSize; } - } else { - data = malloc(newSize); - if (data) dataSize = newSize; } }