1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-11 21:16:02 +01:00

libexpr: Call destructor on exception_ptr

This uses `gc_cleanup` to call the exception_ptr destructor when the
`Failed` is collected.
I don't know exactly how bad it is to deallocate `std::exception_ptr`
without destruction, but I guess it ranges from small leak to UB and crash.
This commit is contained in:
Robert Hensing 2025-09-09 06:01:41 +02:00
parent 6de4db100f
commit 9aa3cc9c8f

View file

@ -268,9 +268,22 @@ struct ValueBase
Value * const * elems;
};
struct Failed : gc
/**
Representation of an evaluation that previously failed.
`Value` references `Failed` by packed pointer, and its `new` is GC managed.
@see gc_cleanup std::exception_ptr
*/
class Failed : public gc_cleanup
{
public:
std::exception_ptr ex;
Failed(std::exception_ptr && ex)
: ex(ex)
{
}
};
};
@ -1075,7 +1088,7 @@ public:
inline void mkFailed() noexcept
{
setStorage(new Value::Failed{.ex = std::current_exception()});
setStorage(new Value::Failed(std::current_exception()));
}
bool isList() const noexcept