diff options
author | Aliaksey Kandratsenka <alk@tut.by> | 2014-05-03 17:38:14 -0700 |
---|---|---|
committer | Aliaksey Kandratsenka <alk@tut.by> | 2014-05-03 17:38:14 -0700 |
commit | 0807476f56b9dc024375467be0f0b07fae3ee7fb (patch) | |
tree | a7af1778f2eea6ea6be605ee8fc64e36c47dcf20 | |
parent | facd7e83b341e069875b7c1cd7774cf671d932b5 (diff) | |
download | gperftools-0807476f56b9dc024375467be0f0b07fae3ee7fb.tar.gz |
issue-620: windows dll patching: fixed delete of old stub code
After code for issue 359 was applied PreamblePatcher started using
it's own code to manage memory of stub code fragments. It's not using
new[] anymore. And it automatically frees stub code memory on
Unpatch.
Clearly, author of that code forgot to remote that no more needed
delete call. With that delete call we end up trying to free memory
that was never allocated with any of known allocators and crash.
-rw-r--r-- | src/windows/patch_functions.cc | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/windows/patch_functions.cc b/src/windows/patch_functions.cc index 2b1923e..ff1bec7 100644 --- a/src/windows/patch_functions.cc +++ b/src/windows/patch_functions.cc @@ -548,13 +548,10 @@ bool LibcInfoWithPatchFunctions<T>::Patch(const LibcInfo& me_info) { if (windows_fn_[i] && windows_fn_[i] != perftools_fn_[i]) { // if origstub_fn_ is not NULL, it's left around from a previous // patch. We need to set it to NULL for the new Patch call. - // Since we've patched Unpatch() not to delete origstub_fn_ (it - // causes problems in some contexts, though obviously not this - // one), we should delete it now, before setting it to NULL. - // NOTE: casting from a function to a pointer is contra the C++ - // spec. It's not safe on IA64, but is on i386. We use - // a C-style cast here to emphasize this is not legal C++. - delete[] (char*)(origstub_fn_[i]); + // + // Note that origstub_fn_ was logically freed by + // PreamblePatcher::Unpatch, so we don't have to do anything + // about it. origstub_fn_[i] = NULL; // Patch() will fill this in CHECK_EQ(sidestep::SIDESTEP_SUCCESS, PreamblePatcher::Patch(windows_fn_[i], perftools_fn_[i], |