diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index a82262704..76f2e721a 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -41,8 +41,15 @@ void BufferedSink::operator () (const unsigned char * data, size_t len) void BufferedSink::flush() { if (bufPos == 0) return; - write(buffer, bufPos); - bufPos = 0; + size_t n = bufPos; + bufPos = 0; // don't trigger the assert() in ~BufferedSink() + write(buffer, n); +} + + +FdSink::~FdSink() +{ + try { flush(); } catch (...) { ignoreException(); } } diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh index a0588668f..a155f6681 100644 --- a/src/libutil/serialise.hh +++ b/src/libutil/serialise.hh @@ -71,7 +71,7 @@ struct FdSink : BufferedSink FdSink() : fd(-1) { } FdSink(int fd) : fd(fd) { } - ~FdSink() { flush(); } + ~FdSink(); void write(const unsigned char * data, size_t len); };