From 8a58d6b2d976b31384707cb8646dbcd80c3308d5 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sun, 28 Jan 2024 14:46:30 -0800 Subject: [PATCH] Removing `Py_DECREF(self)` that leads to MSAN failure (Google toolchain). ``` ==6380==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x5611589c9a58 in Py_DECREF third_party/python_runtime/v3_11/Include/object.h:537:9 ... Uninitialized value was created by a heap deallocation #0 0x5611552757b0 in free third_party/llvm/llvm-project/compiler-rt/lib/msan/msan_interceptors.cpp:218:3 #1 0x56115898e06b in _PyMem_RawFree third_party/python_runtime/v3_11/Objects/obmalloc.c:154:5 #2 0x56115898f6ad in PyObject_Free third_party/python_runtime/v3_11/Objects/obmalloc.c:769:5 #3 0x561158271bcc in PyObject_GC_Del third_party/python_runtime/v3_11/Modules/gcmodule.c:2407:5 #4 0x7f21224b070c in pybind11_object_dealloc third_party/pybind11/include/pybind11/detail/class.h:483:5 #5 0x5611589c2ed0 in subtype_dealloc third_party/python_runtime/v3_11/Objects/typeobject.c:1463:5 ... ``` --- include/pybind11/detail/class.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index 0d554391..815b93f8 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -351,8 +351,7 @@ extern "C" inline int tp_init_intercepted(PyObject *self, PyObject *args, PyObje } int status = (*derived_tp_init->second)(self, args, kw); if (status == 0 && !ensure_base_init_functions_were_called(self)) { - Py_DECREF(self); - return -1; + return -1; // No Py_DECREF here. } return status; }