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

Inline fname2char to fix memory leak #6329

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
inline fname2char to fix #6319
  • Loading branch information
nulano committed May 24, 2022
commit 09da6fa73babd4dd48c038dd8a06196be44702d3
21 changes: 8 additions & 13 deletions src/Tk/tkImaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,6 @@ load_tkinter_funcs(void) {
* tkinter dynamic library (module).
*/

/* From module __file__ attribute to char *string for dlopen. */
char *
fname2char(PyObject *fname) {
PyObject *bytes;
bytes = PyUnicode_EncodeFSDefault(fname);
if (bytes == NULL) {
return NULL;
}
return PyBytes_AsString(bytes);
}

#include <dlfcn.h>

void *
Expand Down Expand Up @@ -442,7 +431,7 @@ load_tkinter_funcs(void) {
int ret = -1;
void *main_program, *tkinter_lib;
char *tkinter_libname;
PyObject *pModule = NULL, *pString = NULL;
PyObject *pModule = NULL, *pString = NULL, *pBytes = NULL;

/* Try loading from the main program namespace first */
main_program = dlopen(NULL, RTLD_LAZY);
Expand All @@ -462,7 +451,12 @@ load_tkinter_funcs(void) {
if (pString == NULL) {
goto exit;
}
tkinter_libname = fname2char(pString);
/* From module __file__ attribute to char *string for dlopen. */
pBytes = PyUnicode_EncodeFSDefault(pString);
if (pBytes == NULL) {
goto exit;
}
tkinter_libname = PyBytes_AsString(pBytes);
if (tkinter_libname == NULL) {
goto exit;
}
Expand All @@ -478,6 +472,7 @@ load_tkinter_funcs(void) {
dlclose(main_program);
Py_XDECREF(pModule);
Py_XDECREF(pString);
Py_XDECREF(pBytes);
return ret;
}
#endif /* end not Windows */