Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev

questions about memory management

 

 

Python dev RSS feed   Index | Next | Previous | View Threaded


julia.lawall at lip6

Apr 28, 2012, 1:06 AM

Post #1 of 2 (124 views)
Permalink
questions about memory management

In Python-3.2.3/Python/import.c, in the function
_PyImport_FixupExtensionUnicode, is any call to PyDict_DelItemString
needed before the final failure returns?

modules = PyImport_GetModuleDict();
if (PyDict_SetItemString(modules, name, mod) < 0)
return -1;
if (_PyState_AddModule(mod, def) < 0) {
PyDict_DelItemString(modules, name);
return -1;
}
if (def->m_size == -1) {
if (def->m_base.m_copy) {
/* Somebody already imported the module,
likely under a different name.
XXX this should really not happen. */
Py_DECREF(def->m_base.m_copy);
def->m_base.m_copy = NULL;
}
dict = PyModule_GetDict(mod);
if (dict == NULL)
return -1;
def->m_base.m_copy = PyDict_Copy(dict);
if (def->m_base.m_copy == NULL)
return -1;
}

In Python-3.2.3/Modules/ossaudiodev.c, in the function build_namelists, is
it intentional that labels is not freed in the last failure case:

if (PyModule_AddObject(module, "control_labels", labels) == -1)
goto error2;
if (PyModule_AddObject(module, "control_names", names) == -1)
goto error1;

return 0;

error2:
Py_XDECREF(labels);
error1:
Py_XDECREF(names);
return -1;

thanks,
julia
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


solipsis at pitrou

Apr 28, 2012, 11:13 AM

Post #2 of 2 (118 views)
Permalink
Re: questions about memory management [In reply to]

Hello Julia,

On Sat, 28 Apr 2012 10:06:52 +0200 (CEST)
Julia Lawall <julia.lawall [at] lip6> wrote:
> In Python-3.2.3/Python/import.c, in the function
> _PyImport_FixupExtensionUnicode, is any call to PyDict_DelItemString
> needed before the final failure returns?

I would say it probably does, but it would need further examination.
Some error-checking code paths in our C code base may lack proper
cleanup, especially when an error is unlikely.
Could you open an issue at http://bugs.python.org with this?

> In Python-3.2.3/Modules/ossaudiodev.c, in the function build_namelists, is
> it intentional that labels is not freed in the last failure case:

The successful call to PyModule_AddObject() steals a reference to
`labels`, so it doesn't need to be decrefed again (the reference is
not owned by the init function anymore).

Regards

Antoine.

> if (PyModule_AddObject(module, "control_labels", labels) == -1)
> goto error2;
> if (PyModule_AddObject(module, "control_names", names) == -1)
> goto error1;
>
> return 0;
>
> error2:
> Py_XDECREF(labels);
> error1:
> Py_XDECREF(names);
> return -1;
>
> thanks,
> julia


_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com

Python dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.