diff options
author | Tyler Brock <tyler.brock@gmail.com> | 2015-03-02 15:57:39 -0500 |
---|---|---|
committer | Tyler Brock <tyler.brock@gmail.com> | 2015-03-03 18:01:19 -0500 |
commit | 69fbf40bdc14d2a0237749a3ad607cfe0f83bc8b (patch) | |
tree | 9d693c897ccc97ea75816dbe7f3de487db2ed1b3 /src/mongo/bson | |
parent | 0c46edb668123e0fb16b1cc2f56f0df68a21649a (diff) | |
download | mongo-69fbf40bdc14d2a0237749a3ad607cfe0f83bc8b.tar.gz |
SERVER-6168 Fix exception memory leak in BSONIteratorSorted
Diffstat (limited to 'src/mongo/bson')
-rw-r--r-- | src/mongo/bson/bsonobjiterator.cpp | 7 | ||||
-rw-r--r-- | src/mongo/bson/bsonobjiterator.h | 7 |
2 files changed, 6 insertions, 8 deletions
diff --git a/src/mongo/bson/bsonobjiterator.cpp b/src/mongo/bson/bsonobjiterator.cpp index a15ceb707b0..c4c922e6580 100644 --- a/src/mongo/bson/bsonobjiterator.cpp +++ b/src/mongo/bson/bsonobjiterator.cpp @@ -51,9 +51,8 @@ namespace mongo { return _cmp( s1 + 1, s2 + 1 ); } - BSONIteratorSorted::BSONIteratorSorted( const BSONObj &o, const ElementFieldCmp &cmp ) { - _nfields = o.nFields(); - _fields = new const char*[_nfields]; + BSONIteratorSorted::BSONIteratorSorted( const BSONObj &o, const ElementFieldCmp &cmp ) + : _nfields(o.nFields()), _fields(new const char*[_nfields]) { int x = 0; BSONObjIterator i( o ); while ( i.more() ) { @@ -61,7 +60,7 @@ namespace mongo { verify( _fields[x-1] ); } verify( x == _nfields ); - std::sort( _fields , _fields + _nfields , cmp ); + std::sort( _fields.get() , _fields.get() + _nfields , cmp ); _cur = 0; } diff --git a/src/mongo/bson/bsonobjiterator.h b/src/mongo/bson/bsonobjiterator.h index 900bb39e77e..aabad674487 100644 --- a/src/mongo/bson/bsonobjiterator.h +++ b/src/mongo/bson/bsonobjiterator.h @@ -30,6 +30,7 @@ #pragma once #include <boost/preprocessor/cat.hpp> // like the ## operator but works with __LINE__ +#include <boost/scoped_array.hpp> #include "mongo/bson/bsonobj.h" #include "mongo/base/disallow_copying.h" @@ -113,8 +114,6 @@ namespace mongo { public: ~BSONIteratorSorted() { verify( _fields ); - delete[] _fields; - _fields = 0; } bool more() { @@ -133,8 +132,8 @@ namespace mongo { BSONIteratorSorted( const BSONObj &o, const ElementFieldCmp &cmp ); private: - const char ** _fields; - int _nfields; + const int _nfields; + const boost::scoped_array<const char *> _fields; int _cur; }; |