Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 286eeda

Browse files
committed
Get dlerror() immediately after dlclose() fails.
Otherwise the second dlclose() could clear the exception set by the first one.
1 parent efd66d4 commit 286eeda

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/_tkagg.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,16 @@ void load_tkinter_funcs(void)
324324

325325
exit:
326326
// We don't need to keep a reference open as the main program & tkinter
327-
// have been imported. Use a non-short-circuiting "or" to try closing both
328-
// handles before handling errors.
329-
if ((main_program && dlclose(main_program))
330-
| (tkinter_lib && dlclose(tkinter_lib))) {
327+
// have been imported. Try to close each library separately (otherwise the
328+
// second dlclose could clear a dlerror from the first dlclose).
329+
bool raised_dlerror = false;
330+
if (main_program && dlclose(main_program) && !raised_dlerror) {
331331
PyErr_SetString(PyExc_RuntimeError, dlerror());
332+
raised_dlerror = true;
333+
}
334+
if (tkinter_lib && dlclose(tkinter_lib) && !raised_dlerror) {
335+
PyErr_SetString(PyExc_RuntimeError, dlerror());
336+
raised_dlerror = true;
332337
}
333338
Py_XDECREF(module);
334339
Py_XDECREF(py_path);

0 commit comments

Comments
 (0)