about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/serialise.cc11
-rw-r--r--src/libutil/serialise.hh2
2 files changed, 10 insertions, 3 deletions
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index a82262704ea3..76f2e721a535 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 a0588668f037..a155f6681e2b 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);
 };