summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlina Moravcova Varekova <pmoravco@redhat.com>2017-02-21 11:48:27 +0100
committerPanu Matilainen <pmatilai@redhat.com>2017-10-26 10:40:47 +0300
commitae4d6eb9783496e18d125f618cabc19100df62e8 (patch)
tree97608f56511fa119e3e8b29cf70e4565f70e7463
parent12fc3389fcfb037e54e3a0054d40cff5ef7354d2 (diff)
downloadrpm-ae4d6eb9783496e18d125f618cabc19100df62e8.tar.gz
Fix number of references on spec_Type (#114)
After creating a specPkg from a spec file we must increase spec file reference counter. Otherwise spec file may be accidentally deallocated and usage of SpecPkg can cause an error. (cherry picked from commit 34b61a1f82f6f9b675ab4ca820b6255af63680f1)
-rw-r--r--python/spec-py.c14
-rw-r--r--python/spec-py.h2
2 files changed, 12 insertions, 4 deletions
diff --git a/python/spec-py.c b/python/spec-py.c
index f710f5c87..753afbad4 100644
--- a/python/spec-py.c
+++ b/python/spec-py.c
@@ -45,8 +45,14 @@ struct specPkgObject_s {
PyObject_HEAD
/*type specific fields */
rpmSpecPkg pkg;
+ specObject *source_spec;
};
+static void specPkg_dealloc(specPkgObject * s)
+{
+ Py_DECREF(s->source_spec);
+}
+
static PyObject *pkgGetSection(rpmSpecPkg pkg, int section)
{
char *sect = rpmSpecPkgGetSection(pkg, section);
@@ -95,7 +101,7 @@ PyTypeObject specPkg_Type = {
"rpm.specpkg", /* tp_name */
sizeof(specPkgObject), /* tp_size */
0, /* tp_itemsize */
- 0, /* tp_dealloc */
+ (destructor) specPkg_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
@@ -227,7 +233,7 @@ static PyObject * spec_get_packages(specObject *s, void *closure)
iter = rpmSpecPkgIterInit(s->spec);
while ((pkg = rpmSpecPkgIterNext(iter)) != NULL) {
- PyObject *po = specPkg_Wrap(&specPkg_Type, pkg);
+ PyObject *po = specPkg_Wrap(&specPkg_Type, pkg, s);
if (!po) {
rpmSpecPkgIterFree(iter);
Py_DECREF(pkgList);
@@ -350,12 +356,14 @@ spec_Wrap(PyTypeObject *subtype, rpmSpec spec)
return (PyObject *) s;
}
-PyObject * specPkg_Wrap(PyTypeObject *subtype, rpmSpecPkg pkg)
+PyObject * specPkg_Wrap(PyTypeObject *subtype, rpmSpecPkg pkg, specObject *source)
{
specPkgObject * s = (specPkgObject *)subtype->tp_alloc(subtype, 0);
if (s == NULL) return NULL;
s->pkg = pkg;
+ s->source_spec = source;
+ Py_INCREF(s->source_spec);
return (PyObject *) s;
}
diff --git a/python/spec-py.h b/python/spec-py.h
index 558fbf207..65b8dc3d7 100644
--- a/python/spec-py.h
+++ b/python/spec-py.h
@@ -13,6 +13,6 @@ extern PyTypeObject specPkg_Type;
#define specPkgObject_Check(v) ((v)->ob_type == &specPkg_Type)
PyObject * spec_Wrap(PyTypeObject *subtype, rpmSpec spec);
-PyObject * specPkg_Wrap(PyTypeObject *subtype, rpmSpecPkg pkg);
+PyObject * specPkg_Wrap(PyTypeObject *subtype, rpmSpecPkg pkg, specObject *source);
#endif /* RPMPYTHON_SPEC */