Skip to content

Commit 92cebaa

Browse files
authored
gh-120568: fix file leak in PyUnstable_CopyPerfMapFile (#120569)
1 parent b337aef commit 92cebaa

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: Python/sysmodule.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -2509,16 +2509,16 @@ PyAPI_FUNC(void) PyUnstable_PerfMapState_Fini(void) {
25092509

25102510
PyAPI_FUNC(int) PyUnstable_CopyPerfMapFile(const char* parent_filename) {
25112511
#ifndef MS_WINDOWS
2512-
FILE* from = fopen(parent_filename, "r");
2513-
if (!from) {
2514-
return -1;
2515-
}
25162512
if (perf_map_state.perf_map == NULL) {
25172513
int ret = PyUnstable_PerfMapState_Init();
25182514
if (ret != 0) {
25192515
return ret;
25202516
}
25212517
}
2518+
FILE* from = fopen(parent_filename, "r");
2519+
if (!from) {
2520+
return -1;
2521+
}
25222522
char buf[4096];
25232523
PyThread_acquire_lock(perf_map_state.map_lock, 1);
25242524
int fflush_result = 0, result = 0;

0 commit comments

Comments
 (0)