File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -215,7 +215,7 @@ class core::impl {
215215 }
216216 }
217217
218- ~frame () {
218+ void close () {
219219 if (is_array) {
220220 if (!bson_append_array_end (parent, &bson)) {
221221 throw bsoncxx::exception{error_code::k_cannot_end_appending_array};
Original file line number Diff line number Diff line change 2323namespace bsoncxx {
2424BSONCXX_INLINE_NAMESPACE_BEGIN
2525
26+ // Note: This stack is only intended for use with the 'frame' type in
27+ // builder core.cpp.
2628template <typename T, std::size_t size>
2729class stack {
2830 public:
2931 stack () : _bucket_index(0 ), _bucket_size(size), _is_empty(true ) {}
3032
3133 ~stack () {
3234 while (!empty ()) {
33- pop_back ();
35+ // If you are using a stack<core::impl::frame> inside a
36+ // builder::core object, then either one of two things is
37+ // true:
38+ //
39+ // 1) core::impl::is_viewable is true, so the stack is
40+ // empty, we aren't going to get here.
41+ //
42+ // OR
43+ //
44+ // 2) The stack isn't empty, so the builder wasn't in a
45+ // viewable state when we were destroying its internal
46+ // stack. We have a partially constructed but
47+ // un-observable BSON document. We don't need to call
48+ // close, which might fail. Just call _dec to properly
49+ // invoke the non-failing frame destructor.
50+ _dec ();
3451 }
3552
3653 while (!_buckets.empty ()) {
@@ -59,6 +76,7 @@ class stack {
5976 }
6077
6178 void pop_back () {
79+ _get_ptr ()->close ();
6280 _dec ();
6381 }
6482
You can’t perform that action at this time.
0 commit comments