Permalink
Browse files

add destructor/free for mysql result

  • Loading branch information...
1 parent 818bb25 commit 479396b93e2d3799e249215583da7dc00a5f537d @ssinghi ssinghi committed with Aug 15, 2010
Showing with 14 additions and 4 deletions.
  1. +12 −4 src/mysql_bindings_result.cc
  2. +2 −0 src/mysql_bindings_result.h
@@ -37,7 +37,9 @@ void MysqlConn::MysqlResult::Init(Handle<Object> target) {
MysqlConn::MysqlResult::MysqlResult(): EventEmitter() {}
-MysqlConn::MysqlResult::~MysqlResult() {}
+MysqlConn::MysqlResult::~MysqlResult() {
+ this->Free();
+}
void MysqlConn::MysqlResult::AddFieldProperties(
Local<Object> &js_field_obj,
@@ -450,6 +452,13 @@ Handle<Value> MysqlConn::MysqlResult::FieldTell(const Arguments& args) {
return scope.Close(js_result);
}
+void MysqlConn::MysqlResult::Free() {
+ if (_res) {
+ mysql_free_result(_res);
+ _res = NULL;
+ }
+}
+
Handle<Value> MysqlConn::MysqlResult::Free(const Arguments& args) {
HandleScope scope;
@@ -460,10 +469,9 @@ Handle<Value> MysqlConn::MysqlResult::Free(const Arguments& args) {
return scope.Close(False());
}
- mysql_free_result(res->_res);
- res->_res = NULL;
+ res->Free();
- return Undefined();
+ return scope.Close(True());
}
Handle<Value> MysqlConn::MysqlResult::NumRows(const Arguments& args) {
@@ -46,6 +46,8 @@ class MysqlConn::MysqlResult : public node::EventEmitter {
MYSQL_FIELD field,
char* field_value);
+ void Free();
+
protected:
MYSQL_RES *_res;

0 comments on commit 479396b

Please sign in to comment.