Skip to content

Commit

Permalink
add check and fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesneimog committed Dec 16, 2023
1 parent dec2e04 commit 2d87657
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2d87657

Please # to comment.