summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2011-07-01 14:25:47 +0300
committerPanu Matilainen <pmatilai@redhat.com>2011-07-01 14:25:47 +0300
commit3f77c3146da46a49f44b17fa66139fbe2dd9e45c (patch)
tree08ac2fee915bd747b9f7e340ef0ef3823cb9840d /python
parent7214b2e0a271b7a7b3df312c58593878cbf56504 (diff)
downloadlibrpm-tizen-3f77c3146da46a49f44b17fa66139fbe2dd9e45c.tar.gz
librpm-tizen-3f77c3146da46a49f44b17fa66139fbe2dd9e45c.tar.bz2
librpm-tizen-3f77c3146da46a49f44b17fa66139fbe2dd9e45c.zip
Fix/sanitize rpm.ts python object creation a bit
- Move all actual initialization work into tp_init, permit reinitialization without leaking and use PyType_GenericNew for tp_new.
Diffstat (limited to 'python')
-rw-r--r--python/rpmts-py.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/python/rpmts-py.c b/python/rpmts-py.c
index cabea1c90..276dbd532 100644
--- a/python/rpmts-py.c
+++ b/python/rpmts-py.c
@@ -726,18 +726,6 @@ static void rpmts_dealloc(rpmtsObject * s)
Py_TYPE(s)->tp_free((PyObject *)s);
}
-static PyObject * rpmts_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
-{
- rpmtsObject * s = (rpmtsObject *)subtype->tp_alloc(subtype, 0);
- if (s == NULL) return NULL;
-
- s->ts = rpmtsCreate();
- s->scriptFd = NULL;
- s->tsi = NULL;
- s->keyList = PyList_New(0);
- return (PyObject *) s;
-}
-
static int rpmts_init(rpmtsObject *s, PyObject *args, PyObject *kwds)
{
char * rootDir = "/";
@@ -748,6 +736,16 @@ static int rpmts_init(rpmtsObject *s, PyObject *args, PyObject *kwds)
&rootDir, &vsflags))
return -1;
+ rpmtsiFree(s->tsi);
+ rpmtsFree(s->ts);
+ Py_XDECREF(s->scriptFd);
+ Py_XDECREF(s->keyList);
+
+ s->ts = rpmtsCreate();
+ s->scriptFd = NULL;
+ s->tsi = NULL;
+ s->keyList = PyList_New(0);
+
(void) rpmtsSetRootDir(s->ts, rootDir);
/* XXX: make this use common code with rpmts_SetVSFlags() to check the
* python objects */
@@ -897,7 +895,7 @@ PyTypeObject rpmts_Type = {
0, /* tp_dictoffset */
(initproc) rpmts_init, /* tp_init */
0, /* tp_alloc */
- (newfunc) rpmts_new, /* tp_new */
+ PyType_GenericNew, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
};