Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42bcf37

Browse files
committed
Issue #26588: Optimize tracemalloc_realloc()
No need to remove the old trace if the memory block didn't move.
1 parent d65e0c7 commit 42bcf37

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Modules/_tracemalloc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,12 @@ tracemalloc_realloc(void *ctx, void *ptr, size_t new_size)
633633
/* an existing memory block has been resized */
634634

635635
TABLES_LOCK();
636-
REMOVE_TRACE(ptr);
636+
637+
/* tracemalloc_add_trace() updates the trace if there is already
638+
a trace at address (domain, ptr2) */
639+
if (ptr2 != ptr) {
640+
REMOVE_TRACE(ptr);
641+
}
637642

638643
if (ADD_TRACE(ptr2, new_size) < 0) {
639644
/* Memory allocation failed. The error cannot be reported to

0 commit comments

Comments
 (0)