Skip to content

Commit 19f6c87

Browse files
code review
1 parent 0e94835 commit 19f6c87

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Python/tracemalloc.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,14 +1213,16 @@ PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr,
12131213
}
12141214
PyGILState_STATE gil_state = PyGILState_Ensure();
12151215
TABLES_LOCK();
1216-
// Check again now that we hold the lock
1217-
if (!tracemalloc_config.tracing) {
1218-
TABLES_UNLOCK();
1219-
PyGILState_Release(gil_state);
1216+
1217+
int result;
1218+
if (tracemalloc_config.tracing) {
1219+
result = tracemalloc_add_trace_unlocked(domain, ptr, size);
1220+
}
1221+
else {
12201222
/* tracemalloc is not tracing: do nothing */
1221-
return -2;
1223+
result = -2;
12221224
}
1223-
int result = tracemalloc_add_trace_unlocked(domain, ptr, size);
1225+
12241226
TABLES_UNLOCK();
12251227
PyGILState_Release(gil_state);
12261228
return result;
@@ -1236,15 +1238,19 @@ PyTraceMalloc_Untrack(unsigned int domain, uintptr_t ptr)
12361238
}
12371239

12381240
TABLES_LOCK();
1239-
// Check again now that we hold the lock
1240-
if (!tracemalloc_config.tracing) {
1241-
TABLES_UNLOCK();
1241+
1242+
int result;
1243+
if (tracemalloc_config.tracing) {
1244+
tracemalloc_remove_trace_unlocked(domain, ptr);
1245+
result = 0;
1246+
}
1247+
else {
12421248
/* tracemalloc is not tracing: do nothing */
1243-
return -2;
1249+
result = -2;
12441250
}
1245-
tracemalloc_remove_trace_unlocked(domain, ptr);
1251+
12461252
TABLES_UNLOCK();
1247-
return 0;
1253+
return result;
12481254
}
12491255

12501256

0 commit comments

Comments
 (0)