Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py_DECREF seems to be missing in Java_jep_python_PyObject_setAttr #538

Open
CHanzyLazer opened this issue Jun 17, 2024 · 1 comment
Open
Labels

Comments

@CHanzyLazer
Copy link

Describe the bug
Py_DECREF seems to be missing in Java_jep_python_PyObject_setAttr, witch will cause memory leak when using setAttr of PyObject.

To Reproduce

try (SharedInterpreter inter = new SharedInterpreter()) {
    inter.exec("class Simple:\n" +
               "    def __init__(self, id):\n" +
               "        self.member = None\n"+
               "        self.id = id\n" +
               "    def __del__(self):\n" +
               "        print('obj' + str(self.id) + ' del')"
    );
    PyCallable simple = inter.getValue("Simple", PyCallable.class);
    PyObject obj1 = simple.callAs(PyObject.class, 1);
    PyObject obj2 = simple.callAs(PyObject.class, 2);
    obj1.setAttr("member", obj2);
}

Output:

obj1 del

So only obj1 was deleted, while obj2 leaked.

Expected behavior

Output:

obj1 del
obj2 del

Both obj1 and obj2 should be deleted.

@bsteffensmeier
Copy link
Member

Thank you very much! I have created a PR with a fix, #539, please review it if you can. I plan to include the fix in the 4.2.1 release of Jep.

@ndjensen ndjensen added the defect label Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants