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; } }