@@ -1919,8 +1919,8 @@ get_current_rss(void)
1919
1919
if (GetProcessMemoryInfo (hProcess , & pmc , sizeof (pmc ))) {
1920
1920
// pmc.WorkingSetSize is in bytes. Convert to KB.
1921
1921
return (Py_ssize_t )(pmc .WorkingSetSize / 1024 );
1922
- } else {
1923
- CloseHandle ( hProcess );
1922
+ }
1923
+ else {
1924
1924
return -1 ;
1925
1925
}
1926
1926
@@ -1944,6 +1944,11 @@ get_current_rss(void)
1944
1944
}
1945
1945
fclose (fp );
1946
1946
1947
+ // Sanity check
1948
+ if (rss_pages < 0 || rss_pages > 1000000000 ) {
1949
+ return -1 ;
1950
+ }
1951
+
1947
1952
// Convert unit to KB
1948
1953
return (Py_ssize_t )rss_pages * (page_size_bytes / 1024 );
1949
1954
@@ -1989,7 +1994,8 @@ get_current_rss(void)
1989
1994
// kp[0] contains the info for our process
1990
1995
// ki_rssize is in pages. Convert to KB.
1991
1996
rss_kb = (Py_ssize_t )kp -> ki_rssize * page_size_kb ;
1992
- } else {
1997
+ }
1998
+ else {
1993
1999
// Process with PID not found, shouldn't happen for self.
1994
2000
rss_kb = -1 ;
1995
2001
}
@@ -2021,7 +2027,8 @@ get_current_rss(void)
2021
2027
if (len > 0 ) {
2022
2028
// p_vm_rssize is in pages on OpenBSD. Convert to KB.
2023
2029
return (Py_ssize_t )kp .p_vm_rssize * page_size_kb ;
2024
- } else {
2030
+ }
2031
+ else {
2025
2032
// Process info not returned
2026
2033
return -1 ;
2027
2034
}
@@ -2060,10 +2067,10 @@ gc_should_collect_rss(GCState *gcstate)
2060
2067
// The RSS has not increased enough, defer the collection and clear
2061
2068
// the young object count so we don't check RSS again on the next call
2062
2069
// to gc_should_collect().
2063
- Py_BEGIN_CRITICAL_SECTION_MUT (& gcstate -> mutex );
2070
+ PyMutex_Lock (& gcstate -> mutex );
2064
2071
gcstate -> deferred_count += gcstate -> young .count ;
2065
2072
gcstate -> young .count = 0 ;
2066
- Py_END_CRITICAL_SECTION ( );
2073
+ PyMutex_Unlock ( & gcstate -> mutex );
2067
2074
return false;
2068
2075
}
2069
2076
}
0 commit comments