Skip to content

Commit

Permalink
Ensure data is copied in memoryTracker::realloc (#886)
Browse files Browse the repository at this point in the history
This bug was introduced by #876.
  • Loading branch information
hainest committed Oct 14, 2020
1 parent e00a91e commit f1733a1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions dyninstAPI/src/binaryEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,15 @@ class memoryTracker : public codeRange {
unsigned get_size() const { return s_; }
void *get_local_ptr() const { return static_cast<void*>(b_.get()); }
void realloc(unsigned newsize) {
if(newsize == s_) return;
b_.reset(new char[newsize]);
s_ = newsize;
if (!b_ && newsize) {
cerr << "Odd: failed to realloc " << newsize << endl;
assert(b_);
if(newsize <= s_) {
// No need to fiddle with the data, just change the size
s_ = newsize;
return;
}
auto *ptr = new char[newsize];
std::copy(b_.get(), b_.get()+s_, ptr);
b_.reset(ptr);
s_ = newsize;
}

bool alloced{false};
Expand Down

0 comments on commit f1733a1

Please sign in to comment.