Skip to content
Permalink
Browse files

db, bugfix: fix crash in MongoCursor.

  • Loading branch information...
xicilion committed Sep 27, 2018
1 parent ebeacf3 commit ded7be35958ab0a5b93fad2dad14949f483104e9
Showing with 28 additions and 11 deletions.
  1. +4 −4 fibjs/include/MongoDB.h
  2. +24 −7 fibjs/src/db/mongo/MongoDB.cpp
@@ -19,6 +19,7 @@ namespace fibjs {
class MongoDB : public MongoDB_base {
public:
MongoDB()
: m_closed(false)
{
m_conn = new mongo();
mongo_init(m_conn);
@@ -50,14 +51,13 @@ class MongoDB : public MongoDB_base {
private:
static result_t mongo_destroy(mongo* conn)
{
if (mongo_is_connected(conn)) {
::mongo_destroy(conn);
delete conn;
}
::mongo_destroy(conn);
delete conn;
return 0;
}

public:
bool m_closed;
mongo* m_conn;
exlib::string m_ns;
};
@@ -225,6 +225,9 @@ result_t MongoDB::open(exlib::string connString)
result_t MongoDB::getCollection(exlib::string name,
obj_ptr<MongoCollection_base>& retVal)
{
if (m_closed)
return CALL_E_INVALID_CALL;

exlib::string nsStr;
const char* ns = name.c_str();

@@ -242,6 +245,9 @@ result_t MongoDB::getCollection(exlib::string name,

result_t MongoDB::_runCommand(bson* command, bson& out, AsyncEvent* ac)
{
if (m_closed)
return CALL_E_INVALID_CALL;

if (ac->isSync())
return CHECK_ERROR(CALL_E_NOSYNC);

@@ -255,6 +261,9 @@ result_t MongoDB::_runCommand(bson* command, bson& out, AsyncEvent* ac)

result_t MongoDB::bsonHandler(bson* command, v8::Local<v8::Object>& retVal)
{
if (m_closed)
return CALL_E_INVALID_CALL;

bson out;

result_t hr = ac__runCommand(command, out);
@@ -271,6 +280,9 @@ result_t MongoDB::bsonHandler(bson* command, v8::Local<v8::Object>& retVal)
result_t MongoDB::runCommand(v8::Local<v8::Object> cmd,
v8::Local<v8::Object>& retVal)
{
if (m_closed)
return CALL_E_INVALID_CALL;

bson bbq;
result_t hr;

@@ -284,6 +296,9 @@ result_t MongoDB::runCommand(v8::Local<v8::Object> cmd,
result_t MongoDB::runCommand(exlib::string cmd, v8::Local<v8::Value> arg,
v8::Local<v8::Object>& retVal)
{
if (m_closed)
return CALL_E_INVALID_CALL;

bson bbq;

bson_init(&bbq);
@@ -296,6 +311,9 @@ result_t MongoDB::runCommand(exlib::string cmd, v8::Local<v8::Value> arg,
result_t MongoDB::_named_getter(exlib::string property,
obj_ptr<MongoCollection_base>& retVal)
{
if (m_closed)
return CALL_E_INVALID_CALL;

return getCollection(property, retVal);
}

@@ -306,20 +324,19 @@ result_t MongoDB::_named_enumerator(v8::Local<v8::Array>& retVal)

result_t MongoDB::oid(exlib::string hexStr, obj_ptr<MongoID_base>& retVal)
{
if (m_closed)
return CALL_E_INVALID_CALL;

retVal = new MongoID(hexStr);
return 0;
}

result_t MongoDB::close(AsyncEvent* ac)
{
if (ac->isSync())
return CHECK_ERROR(CALL_E_NOSYNC);

if (m_conn) {
mongo_destroy(m_conn);
m_conn = NULL;
}
if (m_closed)
return CALL_E_INVALID_CALL;

m_closed = true;
return 0;
}

0 comments on commit ded7be3

Please sign in to comment.
You can’t perform that action at this time.