Skip to content

Commit a091a81

Browse files
committed
libexpr: Clear PosTable contents in EvalState::resetFileCache
Otherwise PosTable grows indefinitely for each reload. Since the total input size is limited to 4GB (uint32_t for byte offset PosIdx) it can get exhausted pretty. This ensures that we don't waste memory on reloads as well.
1 parent 479b6b7 commit a091a81

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/libexpr/eval.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,7 @@ void EvalState::resetFileCache()
11131113
importResolutionCache->clear();
11141114
fileEvalCache->clear();
11151115
inputCache->clear();
1116+
positions.clear();
11161117
}
11171118

11181119
void EvalState::eval(Expr * e, Value & v)

src/libutil/include/nix/util/pos-table.hh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ public:
111111
return o->origin;
112112
return std::monostate{};
113113
}
114+
115+
/**
116+
* Remove all origins from the table.
117+
*/
118+
void clear()
119+
{
120+
auto lines = linesCache.lock();
121+
lines->clear();
122+
origins.clear();
123+
}
114124
};
115125

116126
} // namespace nix

0 commit comments

Comments
 (0)