diff options
author | Mathias Stearn <mathias@10gen.com> | 2013-05-03 15:44:54 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2013-05-03 16:19:02 -0400 |
commit | 8f34ccaa990b80cef9935fcdda844add6f881fac (patch) | |
tree | 06728d4b0a7c12b04619b99d7553a0c629f0a533 /src/mongo/bson/util/builder.h | |
parent | e9f02a3676d816bf1b0190fcb83f8a6b6576e4c2 (diff) | |
download | mongo-8f34ccaa990b80cef9935fcdda844add6f881fac.tar.gz |
SERVER-9538 Only update BufBuilder's len if successfully grew
Otherwise BSONObj destructor will try to grow again to add EOO byte,
causing a double exception and terminate() call.
Diffstat (limited to 'src/mongo/bson/util/builder.h')
-rw-r--r-- | src/mongo/bson/util/builder.h | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h index cfff6114980..a66a736bb5c 100644 --- a/src/mongo/bson/util/builder.h +++ b/src/mongo/bson/util/builder.h @@ -202,18 +202,19 @@ namespace mongo { /* returns the pre-grow write position */ inline char* grow(int by) { int oldlen = l; - l += by; - if ( l > size ) { - grow_reallocate(); + int newLen = l + by; + if ( newLen > size ) { + grow_reallocate(newLen); } + l = newLen; return data + oldlen; } private: /* "slow" portion of 'grow()' */ - void NOINLINE_DECL grow_reallocate() { + void NOINLINE_DECL grow_reallocate(int newLen) { int a = 64; - while( a < l ) + while( a < newLen ) a = a * 2; if ( a > BufferMaxSize ) { std::stringstream ss; |