Skip to content

Commit

Permalink
fix some memory errors
Browse files Browse the repository at this point in the history
  • Loading branch information
orlandov committed Jan 2, 2010
1 parent 28d2f37 commit cf53365
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions bson.cc
Expand Up @@ -71,11 +71,13 @@ bson encodeObject(const Local<Value> element) {
else if (prop_val->IsObject()) {
bson bson(encodeObject(prop_val));
bson_append_bson(&bb, pname, &bson);
bson_destroy(&bson);
}
}

bson bson;
bson_from_buffer(&bson, &bb);

return bson;
}

Expand Down
11 changes: 9 additions & 2 deletions mongo.cc
Expand Up @@ -192,7 +192,8 @@ class Connection : public node::EventEmitter {
int len;
bson_little_endian32(&len, &head.len);

mongo_reply *out = reinterpret_cast<mongo_reply*>(new char[len]);
char *outbuf = new char[len];
mongo_reply *out = reinterpret_cast<mongo_reply*>(outbuf);

out->head.len = len;
bson_little_endian32(&out->head.id, &head.id);
Expand All @@ -212,7 +213,7 @@ class Connection : public node::EventEmitter {
cursor = static_cast<mongo_cursor*>(bson_malloc(sizeof(mongo_cursor)));

ParseReply(out);
delete out;
delete [] outbuf;
}

void
Expand Down Expand Up @@ -285,7 +286,10 @@ class Connection : public node::EventEmitter {
} else {
printf("advancing cursor by one object\n");
bson_init(&cursor->current, bson_addr, 0);

return true;
}
return false;
}

bool ConsumeInput(void) {
Expand Down Expand Up @@ -382,6 +386,9 @@ class Connection : public node::EventEmitter {
bson query_fields_bson = encodeObject(query_fields);

connection->Find(ns, &query_bson, &query_fields_bson);

bson_destroy(&query_bson);
bson_destroy(&query_fields_bson);
return Undefined();
}

Expand Down
2 changes: 1 addition & 1 deletion wscript
Expand Up @@ -20,7 +20,7 @@ def configure(conf):
conf.env.append_value("LIBPATH_MONGO", abspath("./mongo-c-driver/"))
conf.env.append_value("LIB_MONGO", "mongoc")
conf.env.append_value("CPPPATH_MONGO", abspath("./mongo-c-driver/src"))

def build(bld):
# bson = bld.new_task_gen('cxx', 'shlib', 'node_addon')
# bson.target = 'bson'
Expand Down

0 comments on commit cf53365

Please sign in to comment.