Skip to content

Commit

Permalink
Do not call headerLink() in hdr_Wrap()
Browse files Browse the repository at this point in the history
as headers often already have an ref count of 1.
Add headerLink() only where it is necessary.
Plugs memory leaks in Python binding
Resolves: rhbz:#1358467
  • Loading branch information
ffesti committed Oct 21, 2016
1 parent 618860e commit 40326b5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions python/header-py.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
h = headerNew();
} else if (CAPSULE_CHECK(obj)) {
h = CAPSULE_EXTRACT(obj, "rpm._C_Header");
headerLink(h);
} else if (hdrObject_Check(obj)) {
h = headerCopy(((hdrObject*) obj)->h);
} else if (PyBytes_Check(obj)) {
Expand Down Expand Up @@ -778,8 +779,7 @@ PyObject * hdr_Wrap(PyTypeObject *subtype, Header h)
{
hdrObject * hdr = (hdrObject *)subtype->tp_alloc(subtype, 0);
if (hdr == NULL) return NULL;

hdr->h = headerLink(h);
hdr->h = h;
return (PyObject *) hdr;
}

Expand Down
2 changes: 2 additions & 0 deletions python/rpmmi-py.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "rpmsystem-py.h"

#include <rpm/rpmdb.h>
#include <rpm/header.h>

#include "rpmmi-py.h"
#include "header-py.h"
Expand Down Expand Up @@ -74,6 +75,7 @@ rpmmi_iternext(rpmmiObject * s)
s->mi = rpmdbFreeIterator(s->mi);
return NULL;
}
headerLink(h);
return hdr_Wrap(&hdr_Type, h);
}

Expand Down
1 change: 0 additions & 1 deletion python/rpmts-py.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ rpmts_HdrFromFdno(rpmtsObject * s, PyObject *arg)

if (rpmrc == RPMRC_OK) {
ho = hdr_Wrap(&hdr_Type, h);
h = headerFree(h); /* ref held by python object */
} else {
Py_INCREF(Py_None);
ho = Py_None;
Expand Down

0 comments on commit 40326b5

Please sign in to comment.