richardphibel / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
1090e7
From 40326b5724b0cd55a21b2d86eeef344e4826f863 Mon Sep 17 00:00:00 2001
1090e7
From: Florian Festi <ffesti@redhat.com>
1090e7
Date: Thu, 20 Oct 2016 16:06:06 +0200
1090e7
Subject: [PATCH] Do not call headerLink() in hdr_Wrap()
1090e7
1090e7
as headers often already have an ref count of 1.
1090e7
Add headerLink() only where it is necessary.
1090e7
Plugs memory leaks in Python binding
1090e7
Resolves: rhbz:#1358467
1090e7
---
1090e7
 python/header-py.c | 4 ++--
1090e7
 python/rpmmi-py.c  | 2 ++
1090e7
 python/rpmts-py.c  | 1 -
1090e7
 3 files changed, 4 insertions(+), 3 deletions(-)
1090e7
1090e7
diff --git a/python/header-py.c b/python/header-py.c
1090e7
index 63167d9..5d98f89 100644
1090e7
--- a/python/header-py.c
1090e7
+++ b/python/header-py.c
1090e7
@@ -394,6 +394,7 @@ static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
1090e7
 	h = headerNew();
1090e7
     } else if (CAPSULE_CHECK(obj)) {
1090e7
 	h = CAPSULE_EXTRACT(obj, "rpm._C_Header");
1090e7
+	headerLink(h);
1090e7
     } else if (hdrObject_Check(obj)) {
1090e7
 	h = headerCopy(((hdrObject*) obj)->h);
1090e7
     } else if (PyBytes_Check(obj)) {
1090e7
@@ -778,8 +779,7 @@ PyObject * hdr_Wrap(PyTypeObject *subtype, Header h)
1090e7
 {
1090e7
     hdrObject * hdr = (hdrObject *)subtype->tp_alloc(subtype, 0);
1090e7
     if (hdr == NULL) return NULL;
1090e7
-
1090e7
-    hdr->h = headerLink(h);
1090e7
+    hdr->h = h;
1090e7
     return (PyObject *) hdr;
1090e7
 }
1090e7
 
1090e7
diff --git a/python/rpmmi-py.c b/python/rpmmi-py.c
1090e7
index 0e27575..379cafb 100644
1090e7
--- a/python/rpmmi-py.c
1090e7
+++ b/python/rpmmi-py.c
1090e7
@@ -1,6 +1,7 @@
1090e7
 #include "rpmsystem-py.h"
1090e7
 
1090e7
 #include <rpm/rpmdb.h>
1090e7
+#include <rpm/header.h>
1090e7
 
1090e7
 #include "rpmmi-py.h"
1090e7
 #include "header-py.h"
1090e7
@@ -74,6 +75,7 @@ rpmmi_iternext(rpmmiObject * s)
1090e7
 	s->mi = rpmdbFreeIterator(s->mi);
1090e7
 	return NULL;
1090e7
     }
1090e7
+    headerLink(h);
1090e7
     return hdr_Wrap(&hdr_Type, h);
1090e7
 }
1090e7
 
1090e7
diff --git a/python/rpmts-py.c b/python/rpmts-py.c
1090e7
index 13951df..f05371c 100644
1090e7
--- a/python/rpmts-py.c
1090e7
+++ b/python/rpmts-py.c
1090e7
@@ -384,7 +384,6 @@ rpmts_HdrFromFdno(rpmtsObject * s, PyObject *arg)
1090e7
 
1090e7
     if (rpmrc == RPMRC_OK) {
1090e7
 	ho = hdr_Wrap(&hdr_Type, h);
1090e7
-	h = headerFree(h); /* ref held by python object */
1090e7
     } else {
1090e7
 	Py_INCREF(Py_None);
1090e7
 	ho = Py_None;
1090e7
-- 
1090e7
2.9.3
1090e7