diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-09-22 18:53:15 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-09-22 18:53:15 +0300 |
commit | 4c85c7e605ee0312e51c8614d98c4740041ec4e1 (patch) | |
tree | c5e60308b469824efe48bed8c4e04596ecbe4386 /python/rpmds-py.c | |
parent | fdc62b3decfe6a798284fc8c76372092b3ee1f00 (diff) | |
download | librpm-tizen-4c85c7e605ee0312e51c8614d98c4740041ec4e1.tar.gz librpm-tizen-4c85c7e605ee0312e51c8614d98c4740041ec4e1.tar.bz2 librpm-tizen-4c85c7e605ee0312e51c8614d98c4740041ec4e1.zip |
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
Diffstat (limited to 'python/rpmds-py.c')
-rw-r--r-- | python/rpmds-py.c | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/python/rpmds-py.c b/python/rpmds-py.c index 63f52e99d..223c27d9d 100644 --- a/python/rpmds-py.c +++ b/python/rpmds-py.c @@ -475,29 +475,7 @@ static PyMappingMethods rpmds_as_mapping = { */ 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; - 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) { 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 (rpmds_init(s, args, kwds) < 0) { - rpmds_free(s); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Oi:rpmds_new", kwlist, + &hdr_Type, &ho, &to, &flags)) return NULL; - } -if (_rpmds_debug) -fprintf(stderr, "%p ++ ds %p\n", s, s->ds); + if (to != NULL) { + 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; } |