From daf768aeb7e1c0708922204e4d6e11923fbee3be Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 31 Oct 2022 22:06:56 +0100 Subject: [PATCH] fix segfault --- include/pybind11/detail/internals.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 4929a68cee..b98b2bc8e4 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -445,7 +445,7 @@ PYBIND11_NOINLINE internals &get_internals() { } } - if (internals_pp) { + if (internals_pp && *internals_pp) { // We loaded builtins through python's builtins, which means that our `error_already_set` // and `builtin_exception` may be different local classes than the ones set up in the // initial exception translator, below, so add another for our local exception classes. @@ -457,7 +457,9 @@ PYBIND11_NOINLINE internals &get_internals() { (*internals_pp)->registered_exception_translators.push_front(&translate_local_exception); #endif } else { - internals_pp = new internals *(); + if (!internals_pp) { + internals_pp = new internals *(); + } auto *&internals_ptr = *internals_pp; internals_ptr = new internals(); #if defined(WITH_THREAD)