-
Notifications
You must be signed in to change notification settings - Fork 60
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
slpmodule_new() doesn't initialize extra members added by type_new() #22
Comments
Original comment by RMTEW FULL NAME (Bitbucket: rmtew, GitHub: rmtew): I think we need to do releases in a timely fashion, but that we also need to ensure all outstanding bug fixes are applied. Including this one. However, note that the reporter clearly states that in order to reproduce this without his custom allocator, you need to manually corrupt the memory. I was going to say that CCP used Stackless for years and never encountered this problem, but I don't think that's a valid claim. What I can say is that I've used the Stackless interpreter personally for over a decade and this has never been an issue for me. Is this a real problem? Is there a better fix? |
Original comment by Anonymous: This is clearly a fix, and a very small one. But what I really consider an improvement would remove the problem completely: I think flextype should go away, and we should no longer have a module with So in the (hopefully not so) long term, please consider how much it would take to Less code, less complication, same functionality, more simplicity |
Original comment by Kristján Valur Jónsson (Bitbucket: krisvale, GitHub: kristjanvalur): Prerequisite issue #47 has been closed. |
Original comment by Kristján Valur Jónsson (Bitbucket: krisvale, GitHub: kristjanvalur): This problem is likely to have gone away now. Richard, can you verify? |
Original comment by RMTEW FULL NAME (Bitbucket: rmtew, GitHub: rmtew): This wasn't my problem, or something I've ever reproduced, but merely created under my name due to the porting over of issues. If the size of the object is now consistent with the mainline Python object, then we should just close this. |
Original comment by Kristján Valur Jónsson (Bitbucket: krisvale, GitHub: kristjanvalur): Resolved as a side effect of removing flextype. |
Originally reported by: RMTEW FULL NAME (Bitbucket: rmtew, GitHub: rmtew)
(originally reported in Trac by ndade on 2013-06-08 02:47:27)
slpmodule_new() allocates the module using
and that uses PySlpModule_TypePtr->tp_basicsize to determine how many bytes to allocate. On amd64, for example, we expect there to be 40 bytes allocated (sizeof(*m)), but in fact 48 are allocated[1] because tp_basicsize was set to 48 back when the SLP module type was derived in flextype.c. type_new() computed 48 by taking the base type's tp_basicsize of 40 and adding space for one more pointer to hold the weak reference list. Grep for "may_add_weak" in type_new() for the details.
Since this silently added field in *m is not initialized, when the slpmodule object is cleaned up during exit, if that field had a non-NULL value that value gets interpreted as the head of a list of PyWeakReference objects and garbage ensues.
Apparently with the default memory allocators, and perhaps since slpmodule is allocated pretty early, it was NULL. But I've been replacing the GC allocator with my own and there the memory was recycled and the pointer was non-NULL.
The fix is to init the entire memory/object allocated. Something like
does the trick.
You can also reproduce this by making the base memory allocator memset() the memory to random values.
[1] 48 is not including the Py_GC_Head header, which adds another 24 or 32 bytes depending on alignment requirements.
The text was updated successfully, but these errors were encountered: