New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reference leak in thread._local #47960
Comments
This is a copy of a message I sent to the python-dev mailing list; it I noticed that thread._local can leak references if objects are The way this happens is that in Modules/threadmodule.c, in the Py_CLEAR(self->dict);
Py_INCREF(ldict);
self->dict = ldict; If the Py_CLEAR ends up taking away the last reference to an object The recent change (revision 64601 to threadmodule.c) did not address The attached patch (against trunk) is my first attempt at fixing this. However, I am still uncomfortable about the fact that local_getattro |
Hmm, rather than the while loop in your proposal, the proper idiom would be: PyObject *olddict = self->dict;
Py_INCREF(ldict);
self->dict = ldict;
Py_XDECREF(olddict); |
But then if there is a context switch during the last Py_XDECREF, then Functions like local_setattro() use _ldict() more for its side effect |
Well, C code is effectively locked in a single thread until the GIL is |
The specific thing that was happening for me is that an So it's the call to Py_DECREF that's interesting from my point Hence, in the patch I attached, the assignment into self->dict Of course, I'd be all for changing local_getattro/local_setattro |
fyi - This bug and bpo-1868 (http://bugs.python.org/issue1868) seem related. |
Indeed. Therefore, perhaps we could break the problem in two:
|
Ok, then let's continue in bpo-1868. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: