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.
This commit is contained in:
Augustin Cavalier 2024-03-21 13:49:45 -04:00
parent 90edc22bdf
commit 97dc7e3bb2

View File

@ -21,6 +21,12 @@
#include <unistd.h>
#include <SupportDefs.h>
#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);