Skip to content

Commit

Permalink
Fix potentially lost trace due to ordering of WrappedFree
Browse files Browse the repository at this point in the history
  • Loading branch information
timpalpant committed Oct 19, 2019
1 parent 6d1827e commit dc6431d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/malloc_patch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ void *WrappedRealloc(void *ctx, void *ptr, size_t new_size) {
void WrappedFree(void *ctx, void *ptr) {
ReentrantScope scope;
PY_MEM_ALLOCATOR *alloc = reinterpret_cast<PY_MEM_ALLOCATOR *>(ctx);
alloc->free(alloc->ctx, ptr);
// Remove from traced set before delegating to actual free to prevent possible
// race if memory address is reused.
if (scope.is_outer_scope()) {
g_profiler->HandleFree(ptr);
}
alloc->free(alloc->ctx, ptr);
}

PyObjectRef NewPyTrace(const std::vector<FuncLoc> &trace) {
Expand Down

0 comments on commit dc6431d

Please sign in to comment.