Skip to content

Commit

Permalink
free column_data once we receive SQLITE_DONE
Browse files Browse the repository at this point in the history
  • Loading branch information
orlandov committed Mar 26, 2010
1 parent 31d6ecf commit 6357f7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion speedtest.rb
Expand Up @@ -7,7 +7,7 @@

end

count = 100000;
count = 1000000;

t0 = Time.new;
1.upto(count) do
Expand Down
25 changes: 21 additions & 4 deletions sqlite3_bindings.cc
Expand Up @@ -492,7 +492,7 @@ class Sqlite3Db : public EventEmitter {
if (stmt_) sqlite3_finalize(stmt_);
if (column_types_) free(column_types_);
if (column_names_) free(column_names_);
if (column_data_) free(column_data_);
if (column_data_) FreeColumnData();
}

//
Expand Down Expand Up @@ -824,13 +824,31 @@ class Sqlite3Db : public EventEmitter {
}

if (req->result == SQLITE_DONE && sto->column_count_) {
free(sto->column_data_);
sto->column_data_ = NULL;
sto->FreeColumnData();
}

return 0;
}

void FreeColumnData(void) {
if (!column_count_) return;
for (int i = 0; i < column_count_; i++) {
switch (column_types_[i]) {
// XXX why does using String::New make v8 croak here?
case SQLITE_INTEGER:
free(column_data_[i]);
break;
case SQLITE_FLOAT:
free(column_data_[i]);
break;
}
column_data_[i] = NULL;
}

free(column_data_);
column_data_ = NULL;
}

static int EIO_Step(eio_req *req) {
Statement *sto = (class Statement *)(req->data);
sqlite3_stmt *stmt = sto->stmt_;
Expand Down Expand Up @@ -875,7 +893,6 @@ class Sqlite3Db : public EventEmitter {

switch(sto->column_types_[i]) {
case SQLITE_INTEGER:
// XXX reuse this space instead of allocating every time
sto->column_data_[i] = (int *) malloc(sizeof(int));
break;

Expand Down

0 comments on commit 6357f7d

Please sign in to comment.