Skip to content

Commit

Permalink
fix asynchronous query execution, the space allocated should be query…
Browse files Browse the repository at this point in the history
… length + 1
  • Loading branch information
ssinghi authored and Sannis committed Aug 15, 2010
1 parent 453ce24 commit 818bb25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/mysql_bindings_connection.cc
Expand Up @@ -855,6 +855,7 @@ int MysqlConn::EIO_After_Query(eio_req *req) {

query_req->callback.Dispose();
query_req->conn->Unref();
free(query_req->query);
free(query_req);

return 0;
Expand Down Expand Up @@ -883,7 +884,8 @@ int MysqlConn::EIO_Query(eio_req *req) {
}

req->int1 = 1;
if (!mysql_field_count(conn->_conn)) {
query_req->field_count = mysql_field_count(conn->_conn);
if (!query_req->field_count) {
/* no result set - not a SELECT, SHOW, DESCRIBE or EXPLAIN */
req->int1 = 0;
req->result = 0;
Expand All @@ -907,7 +909,6 @@ int MysqlConn::EIO_Query(eio_req *req) {
}

query_req->my_result = my_result;
query_req->field_count = mysql_field_count(conn->_conn);
req->result = 0;

return 0;
Expand All @@ -926,11 +927,11 @@ Handle<Value> MysqlConn::QueryAsync(const Arguments& args) {
}

struct query_request *query_req = (struct query_request *)
calloc(1, sizeof(struct query_request) + query.length());
calloc(1, sizeof(struct query_request));

if (!query_req) {
V8::LowMemoryNotification();
return THREXC("Could not allocate enough memory");
V8::LowMemoryNotification();
return THREXC("Could not allocate enough memory");
}

query_req->result_mode = MYSQLSYNC_STORE_RESULT;
Expand All @@ -940,10 +941,11 @@ Handle<Value> MysqlConn::QueryAsync(const Arguments& args) {
}

query_req->query_length = query.length();
query_req->query = (char *)calloc(query_req->query_length + 1, sizeof(char));

if (snprintf(query_req->query, query_req->query_length, "%s", *query) !=
if (snprintf(query_req->query, query_req->query_length + 1, "%s", *query) !=
query_req->query_length) {
return THREXC("Snprintf() error");
return THREXC("Snprintf() error");
}

query_req->callback = Persistent<Function>::New(callback);
Expand Down
2 changes: 1 addition & 1 deletion src/mysql_bindings_connection.h
Expand Up @@ -222,7 +222,7 @@ class MysqlConn : public node::EventEmitter {
MysqlConn *conn;
int result_mode;
int query_length;
char query[1];
char *query;
MYSQL_RES *my_result;
uint32_t field_count;
};
Expand Down

0 comments on commit 818bb25

Please sign in to comment.