about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2011-12-16T15·45+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2011-12-16T15·45+0000
commit78598d06f0240a15b74720d8f987daeb702318d7 (patch)
tree362d25677710ade8084a5ca417d88224f1c6faa0
parent5a1b9ed0aa3a0c240b667dbe504b61b2b68e4d16 (diff)
* Clean up exception handling.
-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);
 };