From 97dc7e3bb2e2798f06fc6f902fd418cc2d95b007 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 21 Mar 2024 13:49:45 -0400 Subject: [PATCH] AutoDeleter: Add assertion in SetTo that the object is not the one already set. Otherwise we could cause leaks. Most of the time this check should be optimized out, as most uses of AutoDeleter don't invoke SetTo. But it would have caught some bugs in the VFS refactors (which wound up being cancelled out by later commits anyway, but this would've exposed them.) Just invoke debugger(), which calls the kernel debugger when compiled in kernel mode. And define debugger() inline in this header if OS.h is not included to avoid namespace pollution. --- headers/private/shared/AutoDeleter.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/headers/private/shared/AutoDeleter.h b/headers/private/shared/AutoDeleter.h index ac8a441e73..49c52c3a5a 100644 --- a/headers/private/shared/AutoDeleter.h +++ b/headers/private/shared/AutoDeleter.h @@ -21,6 +21,12 @@ #include #include +#ifndef _OS_H +extern "C" { +extern void debugger(const char *message); +} +#endif + namespace BPrivate { @@ -48,6 +54,9 @@ public: inline void SetTo(C *object) { + if (object == fObject && object != NULL) + debugger("identical objects"); + if (object != fObject) { DeleteFunc destructor; destructor(fObject);