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) {
for (int i = 0; i < column_count_; i++) {
switch (column_types_[i]) {
case SQLITE_INTEGER:
free(column_data_[i]);
free((int *)column_data_[i]);
break;
case SQLITE_FLOAT:
free(column_data_[i]);
free((double *) column_data_[i]);
break;
}
column_data_[i] = NULL;
......@@ -607,31 +607,31 @@ int Statement::EIO_Step(eio_req *req) {
sto->column_data_ = (void **) calloc(sto->column_count_,
sizeof(void *));
}
}
for (int i = 0; i < sto->column_count_; i++) {
sto->column_types_[i] = sqlite3_column_type(stmt, i);
for (int i = 0; i < sto->column_count_; i++) {
sto->column_types_[i] = sqlite3_column_type(stmt, i);
// Don't free this!
sto->column_names_[i] = (char *) sqlite3_column_name(stmt, i);
// Don't free this!
sto->column_names_[i] = (char *) sqlite3_column_name(stmt, i);
switch(sto->column_types_[i]) {
case SQLITE_INTEGER:
sto->column_data_[i] = (int *) malloc(sizeof(int));
break;
switch (sto->column_types_[i]) {
case SQLITE_INTEGER:
sto->column_data_[i] = (int *) malloc(sizeof(int));
break;
case SQLITE_FLOAT:
sto->column_data_[i] = (double *) malloc(sizeof(double));
break;
case SQLITE_FLOAT:
sto->column_data_[i] = (double *) malloc(sizeof(double));
break;
case SQLITE_NULL:
sto->column_data_[i] = NULL;
break;
case SQLITE_NULL:
sto->column_data_[i] = NULL;
break;
// no need to allocate memory for strings
// no need to allocate memory for strings
default: {
// unsupported type
default: {
// unsupported type
}
}
}
}
......
var sqlite = require('../sqlite3_bindings');
var sqlite = require('sqlite3_bindings');
var sys = require('sys');
var assert = require('assert');
......@@ -21,7 +21,7 @@ function getRows() {
var d;
if (error) throw error;
if (!row) {
statement.finalize(function () { });
statement.finalize(function () { db.close(function () {}); });
d = ((new Date)-t0)/1000;
puts("**** " + d + "s to fetch " + rows + " rows (" + (rows/d) + "/s)");
return;
......@@ -35,7 +35,7 @@ function getRows() {
}
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;
callback();
});
......@@ -47,8 +47,6 @@ function onInsert(error, info) {
var d;
if (error) throw error;
assert.ok (info && info.last_inserted_id > 0, 'Last inserted ID loading failed');
if (++rows == total) {
d = ((new Date)-t0)/1000;
puts("**** " + d + "s to insert " + rows + " rows (" + (rows/d) + "/s)");
......@@ -60,9 +58,7 @@ db.open(':memory:', function () {
createTable(db, function () {
t0 = new Date();
for (var i = 0; i < total; i++) {
db.prepare("INSERT INTO t1 (alpha) VALUES (1)",
onInsert,
sqlite.EXEC_LAST_INSERT_ID);
db.prepareAndStep("INSERT INTO t1 (alpha) VALUES (1)", onInsert);
}
});
});
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