Skip to content

Commit 636652d

Browse files
committed
fix file leak in PyUnstable_CopyPerfMapFile
1 parent 6f63dff commit 636652d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Python/sysmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,10 +2509,6 @@ 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) {
@@ -2521,6 +2517,10 @@ PyAPI_FUNC(int) PyUnstable_CopyPerfMapFile(const char* parent_filename) {
25212517
}
25222518
char buf[4096];
25232519
PyThread_acquire_lock(perf_map_state.map_lock, 1);
2520+
FILE* from = fopen(parent_filename, "r");
2521+
if (!from) {
2522+
return -1;
2523+
}
25242524
int fflush_result = 0, result = 0;
25252525
while (1) {
25262526
size_t bytes_read = fread(buf, 1, sizeof(buf), from);

0 commit comments

Comments
 (0)