bpo-35993: Fix an incorrect use of released memory#11852
Conversation
| } | ||
| PyMem_RawFree(interp); | ||
| tmp_interp = interp; | ||
| PyMem_RawFree(tmp_interp); |
There was a problem hiding this comment.
I don't understand how the current code can work since PyMem_RawFree() fills freed memory with a byte pattern 0xDB and so interp = interp->next should just crash.
I don't see how this change fix anything: interp still points to freed bytes.
You should read interp->next before PyMem_RawFree(), and so change how the loop is written.
There was a problem hiding this comment.
When PyMem_RawFree(tmp_interp) the tmp_interp point to interp, so you are freed interp too, right?
What about this?
tmp_interp = interp->next;
for (; tmp_interp !=NULL; interp = tmp_interp){
...
tmp_interp = interp->next;
PyMem_RawFree(interp);
}There was a problem hiding this comment.
sure? the last time I have coded in C, that was in 2007 :/ ok
There was a problem hiding this comment.
With a while (interp) should work the same, and the jungling of tmp/interp looks good to me.
There was a problem hiding this comment.
@JulienPalard I have just updated my PR, thanks for the review.
Now, I am going to wait for the review of @vstinner, he is more expert than me with the C language.
| for (; interp != NULL; interp = interp->next) { | ||
| fprintf(stdout, "1. interp: %p\n", interp); | ||
| fprintf(stdout, "2. interp->next: %p\n", interp->next); | ||
| fprintf(stdout, "2.1. _PyRuntime.interpreters.main: %p\n", _PyRuntime.interpreters.main); |
There was a problem hiding this comment.
(Those have been pushed recently to diagnose the "take infinite time to build when this code is added" / "make CI timeout" issue)
There was a problem hiding this comment.
@vstinner yep, just for the debug and because I wanted to show you
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
vstinner
left a comment
There was a problem hiding this comment.
I don't understand how the current code can code: it must crash if I understand correctly.
Is the function called? You may modify the code to add abort(), run the full Python test suite and check if a test does crash.
If there is no crash, would it be possible to add a test?
I prefer this version, especially if you rename tmp_interp to next_interp. |
|
Current version does not compile, runs indefinitely, making CI timeout. |
|
@vstinner it's my fault if my PR is broken after the approval of @JulienPalard. But I am working on it and try to fix it. |
|
@vstinner @ericsnowcurrently the current code is used when you compile Python, but there is no crash (un/fortunately) |
|
@vstinner the code works and the tests pass. no lock on travis. |
Would you mind to elaborate? I would like to make sure that the function is properly tested.
Strange. So maybe the current code is just fine? Or we miss a test. |
|
@vstinner example when you compile python |
|
Ok, but I guess that the code path which trigger the bug is not taken, since according to the bug tracker, it must crash. I guess that no test call this function with more than 1 interpreter. That's why I added @ericsnowcurrently in copy of this change :-) |
|
I am not sure when |
|
@eamanu as you can see my paste in the previous comment, the function is called when we try to compile Python, certainly in the Makefile. |
|
@ericsnowcurrently Any advice for a test for this part? |
| @@ -0,0 +1 @@ | |||
| Fix an incorrect use of released memory. Contributed by Stéphane Wirtel | |||
There was a problem hiding this comment.
Only from this NEWS entry, it's hard to know which code is impacted. I found PyOS_AfterFork_Child() which calls _PyInterpreterState_DeleteExceptMain(). I understand that the bug triggers if an application using multiple interpreters forks... it sounds like a very unusual use case. I propose:
"Fix a crash on fork when using subinterpreters. Contributed by Stéphane Wirtel."
|
@vstinner I have just updated the blurb entry, sorry I didn't see your notification |
|
Thanks @matrixise for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7. |
|
Sorry, @matrixise and @vstinner, I could not cleanly backport this to |
|
Ah, it's a new function in Python 3.8. I didn't know. No need to backport in that case. |
|
@vstinner thank you for the merge ;-) a good news for today ;-) |
https://bugs.python.org/issue35993