about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-03-19T12·50+0100
committertazjin <mail@tazj.in>2020-07-10T22·25+0000
commit5e2151b521b9b8957ab8b53f092a089e6858a2b7 (patch)
tree40bc4dbf10f2138b3a429e581c2911b871cac4f6
parent1937bc86244c0d420f7b40eeb38f14827e92d162 (diff)
fix(3p/nix/repl): Scan NixRepl for GC roots r/1250
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<T>, a wrapper around std::shared_ptr<T>), 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 <rikingcoding@gmail.com>
Reviewed-by: glittershark <grfn@gws.fyi>
-rw-r--r--third_party/nix/src/nix/repl.cc5
1 files changed, 4 insertions, 1 deletions
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 <gc/gc_cpp.h>
+
 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;