Skip to content

Commit

Permalink
Merge pull request #153 from marcgurevitx/fix-rawdata-realloc-ub
Browse files Browse the repository at this point in the history
Free data on RawData.resize(0)
  • Loading branch information
JoeStrout authored Jul 28, 2024
2 parents 1ce1036 + bac7888 commit 264f7dd
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 264f7dd

Please sign in to comment.