From: Panu Matilainen Date: Tue, 22 Sep 2009 15:53:15 +0000 (+0300) Subject: Move allocations out of rpmds object init method X-Git-Tag: rpm-4.8.0-beta1~230 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c85c7e605ee0312e51c8614d98c4740041ec4e1;p=platform%2Fupstream%2Frpm.git 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 --- diff --git a/python/rpmds-py.c b/python/rpmds-py.c index 63f52e9..223c27d 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; }