Skip to content

Commit 34280ce

Browse files
committed
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.
1 parent 920e4f3 commit 34280ce

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/libexpr/include/nix/expr/value.hh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,22 @@ struct ValueBase
268268
Value * const * elems;
269269
};
270270

271-
struct Failed : gc
271+
/**
272+
Representation of an evaluation that previously failed.
273+
274+
`Value` references `Failed` by packed pointer, and its `new` is GC managed.
275+
276+
@see gc_cleanup std::exception_ptr
277+
*/
278+
class Failed : public gc_cleanup
272279
{
280+
public:
273281
std::exception_ptr ex;
282+
283+
Failed(std::exception_ptr && ex)
284+
: ex(ex)
285+
{
286+
}
274287
};
275288
};
276289

@@ -1066,7 +1079,7 @@ public:
10661079

10671080
inline void mkFailed() noexcept
10681081
{
1069-
setStorage(new Value::Failed{.ex = std::current_exception()});
1082+
setStorage(new Value::Failed(std::current_exception()));
10701083
}
10711084

10721085
bool isList() const noexcept

0 commit comments

Comments
 (0)