Commit 35e5534f by Orlando Vazquez

Fix a memory leak introduced when the files were split up.

Column data (name and type) should only be allocated once.
parent 55f8cfb8
...@@ -553,10 +553,10 @@ void Statement::FreeColumnData(void) { ...@@ -553,10 +553,10 @@ void Statement::FreeColumnData(void) {
for (int i = 0; i < column_count_; i++) { for (int i = 0; i < column_count_; i++) {
switch (column_types_[i]) { switch (column_types_[i]) {
case SQLITE_INTEGER: case SQLITE_INTEGER:
free(column_data_[i]); free((int *)column_data_[i]);
break; break;
case SQLITE_FLOAT: case SQLITE_FLOAT:
free(column_data_[i]); free((double *) column_data_[i]);
break; break;
} }
column_data_[i] = NULL; column_data_[i] = NULL;
...@@ -607,7 +607,6 @@ int Statement::EIO_Step(eio_req *req) { ...@@ -607,7 +607,6 @@ int Statement::EIO_Step(eio_req *req) {
sto->column_data_ = (void **) calloc(sto->column_count_, sto->column_data_ = (void **) calloc(sto->column_count_,
sizeof(void *)); sizeof(void *));
} }
}
for (int i = 0; i < sto->column_count_; i++) { for (int i = 0; i < sto->column_count_; i++) {
sto->column_types_[i] = sqlite3_column_type(stmt, i); sto->column_types_[i] = sqlite3_column_type(stmt, i);
...@@ -615,7 +614,7 @@ int Statement::EIO_Step(eio_req *req) { ...@@ -615,7 +614,7 @@ int Statement::EIO_Step(eio_req *req) {
// Don't free this! // Don't free this!
sto->column_names_[i] = (char *) sqlite3_column_name(stmt, i); sto->column_names_[i] = (char *) sqlite3_column_name(stmt, i);
switch(sto->column_types_[i]) { switch (sto->column_types_[i]) {
case SQLITE_INTEGER: case SQLITE_INTEGER:
sto->column_data_[i] = (int *) malloc(sizeof(int)); sto->column_data_[i] = (int *) malloc(sizeof(int));
break; break;
...@@ -635,6 +634,7 @@ int Statement::EIO_Step(eio_req *req) { ...@@ -635,6 +634,7 @@ int Statement::EIO_Step(eio_req *req) {
} }
} }
} }
}
assert(sto->column_types_ && sto->column_data_ && sto->column_names_); assert(sto->column_types_ && sto->column_data_ && sto->column_names_);
......
var sqlite = require('../sqlite3_bindings'); var sqlite = require('sqlite3_bindings');
var sys = require('sys'); var sys = require('sys');
var assert = require('assert'); var assert = require('assert');
...@@ -21,7 +21,7 @@ function getRows() { ...@@ -21,7 +21,7 @@ function getRows() {
var d; var d;
if (error) throw error; if (error) throw error;
if (!row) { if (!row) {
statement.finalize(function () { }); statement.finalize(function () { db.close(function () {}); });
d = ((new Date)-t0)/1000; d = ((new Date)-t0)/1000;
puts("**** " + d + "s to fetch " + rows + " rows (" + (rows/d) + "/s)"); puts("**** " + d + "s to fetch " + rows + " rows (" + (rows/d) + "/s)");
return; return;
...@@ -35,7 +35,7 @@ function getRows() { ...@@ -35,7 +35,7 @@ function getRows() {
} }
function createTable(db, callback) { function createTable(db, callback) {
db.prepare("CREATE TABLE t1 (id INTEGER PRIMARY KEY, alpha INTEGER)", function (error, statement) { db.prepareAndStep("CREATE TABLE t1 (id INTEGER PRIMARY KEY, alpha INTEGER)", function (error, statement) {
if (error) throw error; if (error) throw error;
callback(); callback();
}); });
...@@ -47,8 +47,6 @@ function onInsert(error, info) { ...@@ -47,8 +47,6 @@ function onInsert(error, info) {
var d; var d;
if (error) throw error; if (error) throw error;
assert.ok (info && info.last_inserted_id > 0, 'Last inserted ID loading failed');
if (++rows == total) { if (++rows == total) {
d = ((new Date)-t0)/1000; d = ((new Date)-t0)/1000;
puts("**** " + d + "s to insert " + rows + " rows (" + (rows/d) + "/s)"); puts("**** " + d + "s to insert " + rows + " rows (" + (rows/d) + "/s)");
...@@ -60,9 +58,7 @@ db.open(':memory:', function () { ...@@ -60,9 +58,7 @@ db.open(':memory:', function () {
createTable(db, function () { createTable(db, function () {
t0 = new Date(); t0 = new Date();
for (var i = 0; i < total; i++) { for (var i = 0; i < total; i++) {
db.prepare("INSERT INTO t1 (alpha) VALUES (1)", db.prepareAndStep("INSERT INTO t1 (alpha) VALUES (1)", onInsert);
onInsert,
sqlite.EXEC_LAST_INSERT_ID);
} }
}); });
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment