From 9afcac46ddc4af30a3b98d7dec4958c166d9ba83 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 7 Aug 2026 10:00:23 +0200 Subject: [PATCH 1/3] _raster_source_release_func: fix missing result decref It returns None, so only a singleton ref leaked See #440 --- cairo/pattern.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cairo/pattern.c b/cairo/pattern.c index de6af809..278f79f1 100644 --- a/cairo/pattern.c +++ b/cairo/pattern.c @@ -1018,6 +1018,7 @@ _raster_source_release_func (cairo_pattern_t *pattern, result = NULL; goto error; } + Py_DECREF (result); Py_DECREF (pysurface); PyGILState_Release (gstate); From 5e2e23b85114550a99e93adf9ab8f6b58747e431 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 7 Aug 2026 10:01:24 +0200 Subject: [PATCH 2/3] surface_set_mime_data: decref the interned string mime_intern is never decrefed. Fix by moving ownership to the user_data tuple, which is freed in _destroy_mime_user_data_func, which should mean that it's no longer used as a cairo_user_data_key_t at that point. See #440 --- cairo/surface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cairo/surface.c b/cairo/surface.c index b7b36f29..5f6a446e 100644 --- a/cairo/surface.c +++ b/cairo/surface.c @@ -503,7 +503,7 @@ surface_set_mime_data (PycairoSurface *o, PyObject *args) { mime_intern = PyUnicode_InternFromString (mime_type); surface_capsule = PyCapsule_New(o->surface, NULL, NULL); view_capsule = PyCapsule_New(view, NULL, NULL); - user_data = Py_BuildValue("(NNOO)", surface_capsule, view_capsule, obj, mime_intern); + user_data = Py_BuildValue("(NNON)", surface_capsule, view_capsule, obj, mime_intern); if (user_data == NULL) { PyBuffer_Release (view); PyMem_Free (view); From 4d1e73e0868b4160ccd296eef2bca44447459f73 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 7 Aug 2026 10:04:57 +0200 Subject: [PATCH 3/3] surface_get_mime_data: decref mime_intern See #440 --- cairo/surface.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cairo/surface.c b/cairo/surface.c index 5f6a446e..7909d39c 100644 --- a/cairo/surface.c +++ b/cairo/surface.c @@ -558,6 +558,7 @@ surface_get_mime_data (PycairoSurface *o, PyObject *args) { mime_intern = PyUnicode_InternFromString (mime_type); user_data = cairo_surface_get_user_data( o->surface, (cairo_user_data_key_t *)mime_intern); + Py_DECREF(mime_intern); if (user_data == NULL) { /* In case the mime data wasn't set through the Python API just copy it */