Move allocations out of rpmds object init method
- tp_init can be called several times, allocating from there leaks memory - tp_init gets called automatically on object creation, dont call manually
This commit is contained in:
parent
fdc62b3dec
commit
4c85c7e605
|
@ -475,29 +475,7 @@ static PyMappingMethods rpmds_as_mapping = {
|
||||||
*/
|
*/
|
||||||
static int rpmds_init(rpmdsObject * s, PyObject *args, PyObject *kwds)
|
static int rpmds_init(rpmdsObject * s, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
hdrObject * ho = NULL;
|
|
||||||
PyObject * to = NULL;
|
|
||||||
rpmTag tagN = RPMTAG_REQUIRENAME;
|
|
||||||
rpmsenseFlags flags = 0;
|
|
||||||
char * kwlist[] = {"header", "tag", "flags", NULL};
|
|
||||||
|
|
||||||
if (_rpmds_debug < 0)
|
|
||||||
fprintf(stderr, "*** rpmds_init(%p,%p,%p)\n", s, args, kwds);
|
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Oi:rpmds_init", kwlist,
|
|
||||||
&hdr_Type, &ho, &to, &flags))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (to != NULL) {
|
|
||||||
tagN = tagNumFromPyObject(to);
|
|
||||||
if (tagN == -1) {
|
|
||||||
PyErr_SetString(PyExc_KeyError, "unknown header tag");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s->ds = rpmdsNew(hdrGetHeader(ho), tagN, 0);
|
|
||||||
s->active = 0;
|
s->active = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,15 +495,24 @@ fprintf(stderr, "%p -- ds %p\n", s, s->ds);
|
||||||
static PyObject * rpmds_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
|
static PyObject * rpmds_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
rpmdsObject * s = (void *) PyObject_New(rpmdsObject, subtype);
|
rpmdsObject * s = (void *) PyObject_New(rpmdsObject, subtype);
|
||||||
|
hdrObject * ho = NULL;
|
||||||
|
PyObject * to = NULL;
|
||||||
|
rpmTag tagN = RPMTAG_REQUIRENAME;
|
||||||
|
rpmsenseFlags flags = 0;
|
||||||
|
char * kwlist[] = {"header", "tag", "flags", NULL};
|
||||||
|
|
||||||
/* Perform additional initialization. */
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Oi:rpmds_new", kwlist,
|
||||||
if (rpmds_init(s, args, kwds) < 0) {
|
&hdr_Type, &ho, &to, &flags))
|
||||||
rpmds_free(s);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (_rpmds_debug)
|
if (to != NULL) {
|
||||||
fprintf(stderr, "%p ++ ds %p\n", s, s->ds);
|
tagN = tagNumFromPyObject(to);
|
||||||
|
if (tagN == -1) {
|
||||||
|
PyErr_SetString(PyExc_KeyError, "unknown header tag");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s->ds = rpmdsNew(hdrGetHeader(ho), tagN, 0);
|
||||||
|
|
||||||
return (PyObject *)s;
|
return (PyObject *)s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue