From: Michael Tremer Date: Mon, 12 Jul 2021 10:50:09 +0000 (+0000) Subject: _pakfire: Fix reference counting of keys X-Git-Tag: 0.9.28~1046 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=116a426f2e96c81eb2017db48684b70cf944c781;p=pakfire.git _pakfire: Fix reference counting of keys Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 448304751..33868f5ea 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -457,11 +457,15 @@ static PyObject* Pakfire_get_key(PakfireObject* self, PyObject* args) { if (!PyArg_ParseTuple(args, "s", &pattern)) return NULL; + // Try finding the key struct pakfire_key* key = pakfire_key_get(self->pakfire, pattern); if (!key) Py_RETURN_NONE; - return new_key(&KeyType, key); + PyObject* object = new_key(&KeyType, key); + pakfire_key_unref(key); + + return object; } static PyObject* Pakfire_generate_key(PakfireObject* self, PyObject* args, PyObject* kwds) { @@ -480,7 +484,10 @@ static PyObject* Pakfire_generate_key(PakfireObject* self, PyObject* args, PyObj return NULL; } - return new_key(&KeyType, key); + PyObject* object = new_key(&KeyType, key); + pakfire_key_unref(key); + + return object; } static PyObject* Pakfire_import_key(PakfireObject* self, PyObject* args) { @@ -538,8 +545,12 @@ static PyObject* Pakfire_fetch_key(PakfireObject* self, PyObject* args, PyObject } // Return the result - if (key) - return new_key(&KeyType, key); + if (key) { + PyObject* object = new_key(&KeyType, key); + pakfire_key_unref(key); + + return object; + } Py_RETURN_NONE; }