chantra / rpms / rpm

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