From 492f6d27ed82e63c710a7a0a679a6060e494b21f Mon Sep 17 00:00:00 2001 From: Tian Xia Date: Thu, 5 Mar 2015 21:34:23 -0800 Subject: [PATCH] Fix a segfault in fbson under Mac OS X compiler Summary: The problem appears to be caused by a bug in Mac OS X compiler (http://llvm.org/bugs/show_bug.cgi?id=15337). We need explicitly construct the base object std::ostream(std::streambuf*) with nullptr. Otherwise, ostream will try to delete the underlying streambuf* which apparently is undefined in the Mac OS X compiler. https://github.com/facebook/rocksdb/issues/525 Test Plan: unit test in fbson make all check document_db_test (on mac) Reviewers: IslamAbdelRahman, igor Reviewed By: igor Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D34587 --- third-party/fbson/FbsonStream.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/third-party/fbson/FbsonStream.h b/third-party/fbson/FbsonStream.h index 82c8233ef..6ac132bae 100644 --- a/third-party/fbson/FbsonStream.h +++ b/third-party/fbson/FbsonStream.h @@ -62,7 +62,11 @@ class FbsonInBuffer : public std::streambuf { class FbsonOutStream : public std::ostream { public: explicit FbsonOutStream(uint32_t capacity = 1024) - : head_(nullptr), size_(0), capacity_(capacity), alloc_(true) { + : std::ostream(nullptr), + head_(nullptr), + size_(0), + capacity_(capacity), + alloc_(true) { if (capacity_ == 0) { capacity_ = 1024; } @@ -71,7 +75,11 @@ class FbsonOutStream : public std::ostream { } FbsonOutStream(char* buffer, uint32_t capacity) - : head_(buffer), size_(0), capacity_(capacity), alloc_(false) { + : std::ostream(nullptr), + head_(buffer), + size_(0), + capacity_(capacity), + alloc_(false) { assert(buffer && capacity_ > 0); }