Conversation
I'm calling AI slop, see #2202. av_freep does not call I think this does point to a real issue, so the human directing this is welcome to continue contributing to the project. |
|
Thanks for reviewing quickly. I plead guilty, I used LLMs for investigating and although the fix was not LLM made, it clearly was mostly guided by it. Sorry for posting that without digging further prior to doing it. I also do believe that the issue is real as I’ve seen it happen several times, which is why I wanted to try and fix it. |
|
So I had another look this morning and although I'm not 100% confident what the fix is, I think I may at least have found something that seems off to me. My understanding is that When
... I don't really understand why that would be, as my understanding is deallocation should go "child class first, then parent class, then parent class, etc." and here it seems like attributes of the parent class are being freed first, but adding debug prints shows that it is happening (see at the bottom).
I wasn't able to reproduce the exact crash that I initially reported but it comes from a different platform than my own laptop. However, I was able to produce another crash around approximately the same code path (see here), and I suspect that it might have something to do with how strict/paranoid memory allocators are across systems. I added some debug logging around those code paths (see here, same branch as before) and what it shows is the following: So clearly (unless I'm missing something of course), here we're freeing a pointer through What do you think? |
What is this PR?
This PR is an attempt to fix a crash I have been seeing in some of my code, where the service crashes with the following stack trace.
Looking at the stack trace, it's pretty clear the crash comes from
close_output(definition). What's happening isn't obvious though.Looking further into it, I think what is happening is the following:
OutputContainergets GC'd, the Python reference toself.fileis droppedPyIOFilewhich in turns callav_freep(&self.iocontext)close_outputclose_outputchecks whetherself.file is None. The thing is that, at this point it isNone(as it was cleared bytp_clear) so it callsavio_closep(&self.ptr.pb)avio_closep(&self.ptr.pb)actually has already been called before -- byav_freep(&self.iocontext), which makes the whole thing crash.I believe the reason why things are done this way is that
self.file is Nonecan also mean "the file was opened withavio_open/ with a path", but it conflicts with whattp_cleardoes.The proposed fix is to add a new
bint _avio_openedattribute which will not be cleared (as opposed to a Python object reference/pointer) so the deallocator can just look at this to make the call of whether it should callavio_closep.