Skip to content

Commit daeb949

Browse files
committed
[tracemalloc] initialize gil_state in functions to stop warnings
Initialize PyGILState_STATE gil_state to PyGILState_UNLOCKED in PyTraceMalloc_Track, tracemalloc_alloc, tracemalloc_realloc to stop -Wmaybe-uninitialized warnings on GCC. Behavior is unchanged
1 parent 5f57f69 commit daeb949

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Python/tracemalloc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ tracemalloc_alloc(int need_gil, int use_calloc,
525525
goto done;
526526
}
527527

528-
PyGILState_STATE gil_state;
528+
PyGILState_STATE gil_state = PyGILState_UNLOCKED;
529529
if (need_gil) {
530530
gil_state = PyGILState_Ensure();
531531
}
@@ -575,7 +575,7 @@ tracemalloc_realloc(int need_gil, void *ctx, void *ptr, size_t new_size)
575575
goto done;
576576
}
577577

578-
PyGILState_STATE gil_state;
578+
PyGILState_STATE gil_state = PyGILState_UNLOCKED;
579579
if (need_gil) {
580580
gil_state = PyGILState_Ensure();
581581
}
@@ -1207,11 +1207,14 @@ int
12071207
PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr,
12081208
size_t size)
12091209
{
1210+
PyGILState_STATE gil_state = PyGILState_UNLOCKED;
1211+
12101212
if (_Py_atomic_load_int_relaxed(&tracemalloc_config.tracing) == 0) {
12111213
/* tracemalloc is not tracing: do nothing */
12121214
return -2;
12131215
}
1214-
PyGILState_STATE gil_state = PyGILState_Ensure();
1216+
1217+
gil_state = PyGILState_Ensure();
12151218
TABLES_LOCK();
12161219

12171220
int result;

0 commit comments

Comments
 (0)