diff --git a/MiniScript-cpp/src/ShellIntrinsics.cpp b/MiniScript-cpp/src/ShellIntrinsics.cpp index 3bab145..1225a10 100644 --- a/MiniScript-cpp/src/ShellIntrinsics.cpp +++ b/MiniScript-cpp/src/ShellIntrinsics.cpp @@ -102,15 +102,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; } }