cleanup and fix refleaks

This commit is contained in:
Benjamin Peterson 2012-12-15 00:05:16 -05:00
parent e0a908290c
commit 5cb8a31dc4
1 changed files with 12 additions and 8 deletions

View File

@ -470,8 +470,9 @@ int
_PyImport_FixupExtensionObject(PyObject *mod, PyObject *name, _PyImport_FixupExtensionObject(PyObject *mod, PyObject *name,
PyObject *filename) PyObject *filename)
{ {
PyObject *modules, *dict, *filename_name; PyObject *modules, *dict, *key;
struct PyModuleDef *def; struct PyModuleDef *def;
int res;
if (extensions == NULL) { if (extensions == NULL) {
extensions = PyDict_New(); extensions = PyDict_New();
if (extensions == NULL) if (extensions == NULL)
@ -508,10 +509,12 @@ _PyImport_FixupExtensionObject(PyObject *mod, PyObject *name,
if (def->m_base.m_copy == NULL) if (def->m_base.m_copy == NULL)
return -1; return -1;
} }
filename_name = PyTuple_Pack(2,filename, name); key = PyTuple_Pack(2, filename, name);
if (filename_name == NULL) if (key == NULL)
return -1; return -1;
if (PyDict_SetItem(extensions, filename_name, (PyObject*)def) < 0) res = PyDict_SetItem(extensions, key, (PyObject *)def);
Py_DECREF(key);
if (res < 0)
return -1; return -1;
return 0; return 0;
} }
@ -532,14 +535,15 @@ _PyImport_FixupBuiltin(PyObject *mod, char *name)
PyObject * PyObject *
_PyImport_FindExtensionObject(PyObject *name, PyObject *filename) _PyImport_FindExtensionObject(PyObject *name, PyObject *filename)
{ {
PyObject *mod, *mdict, *filename_name; PyObject *mod, *mdict, *key;
PyModuleDef* def; PyModuleDef* def;
if (extensions == NULL) if (extensions == NULL)
return NULL; return NULL;
filename_name = PyTuple_Pack(2,filename, name); key = PyTuple_Pack(2, filename, name);
if (filename_name == NULL) if (key == NULL)
return NULL; return NULL;
def = (PyModuleDef*)PyDict_GetItem(extensions, filename_name); def = (PyModuleDef *)PyDict_GetItem(extensions, key);
Py_DECREF(key);
if (def == NULL) if (def == NULL)
return NULL; return NULL;
if (def->m_size == -1) { if (def->m_size == -1) {