mongodb の C++ ドライバーからの非常に単純な例で valgrind を使用すると、BSONObj の定義で明示的に GENOID を使用するとすぐに、何かが間違っているように見えます。この問題を示す例を次に示します。
(gcc 4.4.5、boost 1.42、debian 6、mongodb C++ ドライバー 2.2 でテスト済み)
#include <cstdio>
#include <string>
#include "mongo/db/jsobj.h"
main()
{
mongo::BSONObj p = BSON( mongo::GENOID << "name" << "Joe" << "age" << 33 );
std::string s = p.toString();
std::cout << s;
}
valgrind で実行すると、次のメッセージが表示されます。
==2506== Use of uninitialised value of size 8
==2506== at 0x40A66B: mongo::toHexLower(void const*, int) (hex.h:64)
==2506== by 0x40A73F: mongo::OID::str() const (oid.h:66)
==2506== by 0x40A798: mongo::operator<<(mongo::StringBuilderImpl<mongo::TrivialAllocator>&, mongo::OID const&) (oid.h:140)
==2506== by 0x40DCC1: mongo::BSONElement::toString(mongo::StringBuilderImpl<mongo::TrivialAllocator>&, bool, bool, int) const (bson-inl.h:765)
==2506== by 0x40C898: mongo::BSONObj::toString(mongo::StringBuilderImpl<mongo::TrivialAllocator>&, bool, bool, int) const (bson-inl.h:475)
==2506== by 0x40C5A5: mongo::BSONObj::toString(bool, bool) const (bson-inl.h:445)
==2506== by 0x40A1B8: main (mongobug.cc:10)
BSONObj 定義から GENOID を削除すると、問題はなくなります。これは、プロジェクトで mongo::OID::gen() を使用するときに発生する、より複雑ではあるが同様の問題の最小限のバージョンです。
上記の例は、次の公式の mongodb C++ ドライバー チュートリアルから取得したものです。
何が間違っている可能性がありますか?ありがとう、