-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fix GetString memory leak #70
Conversation
Mhh. Indeed this fails with PyFMI, but works with FMI4j... Don't know what to do, because it does leak. |
I'm starting to think this could be a FMI4j bug? I need to check the standard on string handling. For refernce, this work with PyFMI PyObject* value = PyList_GetItem(refs, i);
PyObject* strValue = PyUnicode_AsEncodedString(value, "utf-8", nullptr);
char* src = PyBytes_AsString(strValue);
char* dst = reinterpret_cast<char*>(malloc(strlen(src) + 1));
strcpy_s(dst, strlen(src) + 1, src);
values[i] = dst;
Py_DECREF(strValue); But I dunno if thats correct. It uses less memory in FMI4j, but still seams to leak. Is the caller responsible for deleting |
Hey I don't think this is a bug of FMI4J. I have seen there is a built-in package for tracing Python allocation. Maybe you can get more inside with it? https://docs.python.org/3/library/tracemalloc.html Not: there is another one to correct too 😉
|
From the specification:
So from your latest proposal, could it be that the copied string |
So how I read your excerpt is that we must deallocate the string in another FMI call. Say the next invocation of |
This should do it ! |
I'll fix that once #71 is merged |
# Conflicts: # pythonfmu/pythonfmu-export/cpp/PySlaveInstance.cpp # pythonfmu/pythonfmu-export/headers/pythonfmu/PySlaveInstance.hpp
We should probably release a patch including the two latest bugfixes soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching and fixing this one.
We are almost good. I have just one concern about the buffer clearance not being called within a GIL captured lambda (see comments).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
GetString eats memory. This PR fixes it.
Closes #69