Skip to content

Commit

Permalink
[tools/depends][python3] Patch upstream issue memleak
Browse files Browse the repository at this point in the history
A memleak was found in cpython 3.11.0 that looks to potentially be reasonably serious
Upstream issue is python/cpython#99205
This uses the merged upstream patch python/cpython#99301
until we bump to a newer release (3.11.1+)
  • Loading branch information
fuzzard committed Nov 10, 2022
1 parent 31ceec9 commit 859405e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tools/depends/target/python3/01-fix-memleak-PR99301.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -341,6 +341,7 @@ PyInterpreterState_New(void)
interp = &runtime->_main_interpreter;
assert(interp->id == 0);
assert(interp->next == NULL);
+ assert(interp->_static);

interpreters->main = interp;
}
@@ -355,6 +356,9 @@ PyInterpreterState_New(void)
// Set to _PyInterpreterState_INIT.
memcpy(interp, &initial._main_interpreter,
sizeof(*interp));
+ // We need to adjust any fields that are different from the initial
+ // interpreter (as defined in _PyInterpreterState_INIT):
+ interp->_static = false;

if (id < 0) {
/* overflow or Py_Initialize() not called yet! */
@@ -817,6 +821,7 @@ new_threadstate(PyInterpreterState *interp)
assert(id == 1);
used_newtstate = 0;
tstate = &interp->_initial_thread;
+ assert(tstate->_static);
}
else {
// Every valid interpreter must have at least one thread.
@@ -828,6 +833,9 @@ new_threadstate(PyInterpreterState *interp)
memcpy(tstate,
&initial._main_interpreter._initial_thread,
sizeof(*tstate));
+ // We need to adjust any fields that are different from the initial
+ // thread (as defined in _PyThreadState_INIT):
+ tstate->_static = false;
}
interp->threads.head = tstate;

4 changes: 4 additions & 0 deletions tools/depends/target/python3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ DEPS = ../../Makefile.include Makefile PYTHON3-VERSION ../../download-files.incl
apple.patch \
crosscompile.patch \
darwin_embedded.patch \
01-fix-memleak-PR99301.patch \
10-android-modules.patch \
10-linux-modules.patch \
10-osx-modules.patch \
Expand Down Expand Up @@ -56,6 +57,9 @@ all: .installed-$(PLATFORM)
$(PLATFORM): $(TARBALLS_LOCATION)/$(ARCHIVE).$(HASH_TYPE) $(DEPS)
rm -rf $(PLATFORM)/*; mkdir -p $(PLATFORM)
cd $(PLATFORM); $(ARCHIVE_TOOL) $(ARCHIVE_TOOL_FLAGS) $(TARBALLS_LOCATION)/$(ARCHIVE)
# Temp patch to resolve https://github.com/python/cpython/issues/99205
# Remove in 3.11.1+ bump
cd $(PLATFORM); patch -p1 -i ../01-fix-memleak-PR99301.patch
cd $(PLATFORM); patch -p1 -i ../crosscompile.patch
cd $(PLATFORM); patch -p1 -i ../apple.patch
ifeq ($(OS),darwin_embedded)
Expand Down

0 comments on commit 859405e

Please sign in to comment.