Issue 3095: multiprocessing initializes flags dict unsafely (original) (raw)

Created on 2008-06-12 20:23 by Rhamphoryncus, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
multiprocessing.diff jjt009,2008-06-13 01:05 Patch for multiprocessing.c
Messages (5)
msg68081 - (view) Author: Adam Olsen (Rhamphoryncus) Date: 2008-06-12 20:23
multiprocessing.c currently has code like this: temp = PyDict_New(); if (!temp) return; if (PyModule_AddObject(module, "flags", temp) < 0) return; PyModule_AddObject consumes the reference to temp, so it could conceivable be deleted before the rest of this function finishes.
msg68114 - (view) Author: James Thomas (jjt009) Date: 2008-06-13 01:05
I believe this patch solves the problem. I added the line Py_DECREF(temp) after the code block shown above. I also changed the line if (PyDict_SetItemString(temp, #name, Py_BuildValue("i", name)) < 0) return to if (PyDict_SetItemString(PyObject_GetAttrString(module, "flags"), #name, Py_BuildValue("i", name)) < 0) return
msg68117 - (view) Author: Adam Olsen (Rhamphoryncus) Date: 2008-06-13 01:48
This doesn't look right. PyDict_SetItemString doesn't steal the references passed to it, so your reference to flags will be leaked each time. Besides, I think it's a little cleaner to INCREF it before call PyModule_AddObject, then DECREF it at any point you return. Additionally, I've just noticed that the result of Py_BuildValue is getting leaked. It should be stored to a temporary, added to flags, then the temporary should be released.
msg68129 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-06-13 06:57
I think the easiest way is to just call AddObject after inserting the values. I fixed this, and the leaking BuildValue references, in r64223.
msg68132 - (view) Author: Adam Olsen (Rhamphoryncus) Date: 2008-06-13 07:21
Aww, that's cheating. (Why didn't I think of that?)
History
Date User Action Args
2022-04-11 14:56:35 admin set github: 47345
2008-06-13 07:21:49 Rhamphoryncus set messages: +
2008-06-13 06:57:48 georg.brandl set status: open -> closedresolution: fixedmessages: + nosy: + georg.brandl
2008-06-13 01:48:06 Rhamphoryncus set messages: +
2008-06-13 01:05:57 jjt009 set files: + multiprocessing.diffkeywords: + patchmessages: + nosy: + jjt009
2008-06-12 20:30:37 jnoller set nosy: + roudkerk, jnoller
2008-06-12 20:23:24 Rhamphoryncus create