Skip to content

Commit

Permalink
Free data on RawData.resize(0)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgurevitx authored and borgi committed Nov 21, 2024
1 parent a25aff4 commit 9976661
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions MiniScript-cpp/src/ShellIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 9976661

Please sign in to comment.