Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
if (!this.db) {
throw "Database closed";
}
var stack = stackSave();
var stmt = null;
var originalSqlPtr = null;
var currentSqlPtr = null;
Expand Down Expand Up @@ -993,6 +994,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
throw errCaught;
} finally {
if (originalSqlPtr) _free(originalSqlPtr);
stackRestore(stack);
}
};

Expand Down
48 changes: 48 additions & 0 deletions test/test_issue630.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

exports.test = function(sql, assert) {
"use strict";
var db = new sql.Database();
db.run("CREATE TABLE t (x); INSERT INTO t VALUES (1);");

var before = sql.stackSave();
for (var i = 0; i < 1000; i++) {
db.exec("SELECT x FROM t");
}
assert.strictEqual(
before - sql.stackSave(),
0,
"exec() should not leak stack memory after repeated successful calls"
);

for (var j = 0; j < 100; j++) {
assert.throws(
function () { db.exec("SELECT * FROM does_not_exist"); },
"no such table: does_not_exist",
"exec() should throw for a failing query"
);
}
assert.strictEqual(
before - sql.stackSave(),
0,
"exec() should not leak stack memory after repeated failing calls"
);

// Close the database and all associated statements
db.close();
};

if (module == require.main) {
const target_file = process.argv[2];
const sql_loader = require('./load_sql_lib');
sql_loader(target_file).then((sql)=>{
require('test').run({
'test issue630': function(assert){
exports.test(sql, assert);
}
});
})
.catch((e)=>{
console.error(e);
assert.fail(e);
});
}
Loading