From 5e2151b521b9b8957ab8b53f092a089e6858a2b7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 19 Mar 2020 13:50:01 +0100 Subject: fix(3p/nix/repl): Scan NixRepl for GC roots Backport of https://github.com/NixOS/nix/commit/b244e65cdbc2949af70bd539bf8f3bd2fa952d07 Fixes https://github.com/NixOS/nix/issues/3175 ------ Original fault description by puck: I suspect I found the issue: The Nix Command structs are stored on the heap (using ref, a wrapper around std::shared_ptr), which means that any pointers that the NixRepl struct contains are eligible to be reaped by the GC. This includes, but is not limited to, the Env pointer, which seems to cause most of the random segfaults, or random other values in the environment, which seems to be what @arianvp experienced too. Change-Id: I376d7cfd432daaa6f1fbbf77788ff048082f34e5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1001 Tested-by: BuildkiteCI Reviewed-by: Kane York Reviewed-by: glittershark --- third_party/nix/src/nix/repl.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/third_party/nix/src/nix/repl.cc b/third_party/nix/src/nix/repl.cc index 9431b5b60f..823bb3b88c 100644 --- a/third_party/nix/src/nix/repl.cc +++ b/third_party/nix/src/nix/repl.cc @@ -22,6 +22,9 @@ #include "libutil/finally.hh" #include "nix/command.hh" +#define GC_INCLUDE_NEW +#include + namespace nix { #define ESC_RED "\033[31m" @@ -32,7 +35,7 @@ namespace nix { #define ESC_CYA "\033[36m" #define ESC_END "\033[0m" -struct NixRepl { +struct NixRepl : gc { std::string curDir; EvalState state; Bindings* autoArgs; -- cgit 1.4.1