diff options
author | Mark H Weaver <mhw@netris.org> | 2015-06-10 17:50:27 -0400 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2015-06-10 17:50:27 -0400 |
commit | 14928016556300a6763334d4279c3d117902caaf (patch) | |
tree | d0dc262b14164b82f97dd6e896ca9e93a1fabeea /nix/libutil/serialise.cc | |
parent | 1511e0235525358abb52cf62abeb9457605b5093 (diff) | |
parent | 57cd353d87d6e9e6e882327be70b4d7b5ce863ba (diff) |
Merge branch 'master' into core-updates
Diffstat (limited to 'nix/libutil/serialise.cc')
-rw-r--r-- | nix/libutil/serialise.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/nix/libutil/serialise.cc b/nix/libutil/serialise.cc index 6b71f52c15..9241750750 100644 --- a/nix/libutil/serialise.cc +++ b/nix/libutil/serialise.cc @@ -54,8 +54,24 @@ FdSink::~FdSink() } +size_t threshold = 256 * 1024 * 1024; + +static void warnLargeDump() +{ + printMsg(lvlError, "warning: dumping very large path (> 256 MiB); this may run out of memory"); +} + + void FdSink::write(const unsigned char * data, size_t len) { + static bool warned = false; + if (warn && !warned) { + written += len; + if (written > threshold) { + warnLargeDump(); + warned = true; + } + } writeFull(fd, data, len); } @@ -256,4 +272,15 @@ template Paths readStrings(Source & source); template PathSet readStrings(Source & source); +void StringSink::operator () (const unsigned char * data, size_t len) +{ + static bool warned = false; + if (!warned && s.size() > threshold) { + warnLargeDump(); + warned = true; + } + s.append((const char *) data, len); +} + + } |