From 2d8765704890c65044f76d37cc4bfebd8edfc9d8 Mon Sep 17 00:00:00 2001 From: "Charles K. Neimog" Date: Sat, 16 Dec 2023 10:42:02 -0300 Subject: [PATCH] add check and fix memory leak --- src/utils.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/utils.c b/src/utils.c index 9a8fde3c..1899344d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -220,9 +220,21 @@ PyObject *Py4pdUtils_AddPdObject(t_py *x) { PyModule_AddObject( PyImport_ImportModule("pd"), "py4pd", objectCapsule); // add the capsule to the python interpreter + // create a capsule to t_py to Py Interp. + objectCapsule = PyCapsule_New(x, "py4pd", NULL); + PyObject *pdModule = PyImport_ImportModule("pd"); + int addSucess = + PyModule_AddObject(pdModule, "py4pd", objectCapsule); + if (addSucess != 0) { + pd_error(x, "[py4pd] Failed to add object to Python"); + return NULL; + } + + Py_DECREF(pdModule); } } else { pd_error(x, "[Python] Could not get the main module"); + pd_error(x, "[py4pd] Could not get the main module"); objectCapsule = NULL; } return objectCapsule;