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 committed May 22, 2024
1 parent e85ec61 commit bac7888
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 @@ -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;
}
}

Expand Down

0 comments on commit bac7888

Please sign in to comment.