From fdc62b3decfe6a798284fc8c76372092b3ee1f00 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 22 Sep 2009 18:50:32 +0300 Subject: [PATCH] Move allocations out of rpmfi 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 --- python/rpmfi-py.c | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/python/rpmfi-py.c b/python/rpmfi-py.c index c4c90cf..70bc6db 100644 --- a/python/rpmfi-py.c +++ b/python/rpmfi-py.c @@ -367,30 +367,7 @@ static PyMappingMethods rpmfi_as_mapping = { */ static int rpmfi_init(rpmfiObject * s, PyObject *args, PyObject *kwds) { - hdrObject * ho = NULL; - PyObject * to = NULL; - rpmts ts = NULL; /* XXX FIXME: fiFromHeader should be a ts method. */ - rpmTag tagN = RPMTAG_BASENAMES; - int flags = 0; - char * kwlist[] = {"header", "tag", "flags", NULL}; - -if (_rpmfi_debug < 0) -fprintf(stderr, "*** rpmfi_init(%p,%p,%p)\n", s, args, kwds); - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Oi:rpmfi_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->fi = rpmfiNew(ts, hdrGetHeader(ho), tagN, flags); s->active = 0; - return 0; } @@ -411,14 +388,24 @@ static PyObject * rpmfi_new(PyTypeObject * subtype, PyObject *args, PyObject *kw { rpmfiObject * s = (void *) PyObject_New(rpmfiObject, subtype); - /* Perform additional initialization. */ - if (rpmfi_init(s, args, kwds) < 0) { - rpmfi_free(s); + hdrObject * ho = NULL; + PyObject * to = NULL; + rpmTag tagN = RPMTAG_BASENAMES; + int flags = 0; + char * kwlist[] = {"header", "tag", "flags", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Oi:rpmfi_init", kwlist, + &hdr_Type, &ho, &to, &flags)) return NULL; - } -if (_rpmfi_debug) -fprintf(stderr, "%p ++ fi %p\n", s, s->fi); + if (to != NULL) { + tagN = tagNumFromPyObject(to); + if (tagN == -1) { + PyErr_SetString(PyExc_KeyError, "unknown header tag"); + return NULL; + } + } + s->fi = rpmfiNew(NULL, hdrGetHeader(ho), tagN, flags); return (PyObject *)s; } -- 2.7.4