8000 Address review feedback. · python/cpython@ff2882e · GitHub
[go: up one dir, main page]

Skip to content

Commit ff2882e

Browse files
committed
Address review feedback.
1 parent aabe31d commit ff2882e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Python/gc_free_threading.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,8 +1919,8 @@ get_current_rss(void)
19191919
if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc))) {
19201920
// pmc.WorkingSetSize is in bytes. Convert to KB.
19211921
return (Py_ssize_t)(pmc.WorkingSetSize / 1024);
1922-
} else {
1923-
CloseHandle(hProcess);
1922+
}
1923+
else {
19241924
return -1;
19251925
}
19261926

@@ -1944,6 +1944,11 @@ get_current_rss(void)
19441944
}
19451945
fclose(fp);
19461946

1947+
// Sanity check
1948+
if (rss_pages < 0 || rss_pages > 1000000000) {
1949+
return -1;
1950+
}
1951+
19471952
// Convert unit to KB
19481953
return (Py_ssize_t)rss_pages * (page_size_bytes / 1024);
19491954

@@ -1989,7 +1994,8 @@ get_current_rss(void)
19891994
// kp[0] contains the info for our process
19901995
// ki_rssize is in pages. Convert to KB.
19911996
rss_kb = (Py_ssize_t)kp->ki_rssize * page_size_kb;
1992-
} else {
1997+
}
1998+
else {
19931999
// Process with PID not found, shouldn't happen for self.
19942000
rss_kb = -1;
19952001
}
@@ -2021,7 +2027,8 @@ get_current_rss(void)
20212027
if (len > 0) {
20222028
// p_vm_rssize is in pages on OpenBSD. Convert to KB.
20232029
return (Py_ssize_t)kp.p_vm_rssize * page_size_kb;
2024-
} else {
2030+
}
2031+
else {
20252032
// Process info not returned
20262033
return -1;
20272034
}
@@ -2060,10 +2067,10 @@ gc_should_collect_rss(GCState *gcstate)
20602067
// The RSS has not increased enough, defer the collection and clear
20612068
// the young object count so we don't check RSS again on the next call
20622069
// to gc_should_collect().
2063-
Py_BEGIN_CRITICAL_SECTION_MUT(&gcstate->mutex);
2070+
PyMutex_Lock(&gcstate->mutex);
20642071
gcstate->deferred_count += gcstate->young.count;
20652072
gcstate->young.count = 0;
2066-
Py_END_CRITICAL_SECTION();
2073+
PyMutex_Unlock(&gcstate->mutex);
20672074
return false;
20682075
}
20692076
}

0 commit comments

Comments
 (0)
0