sql-js / sql.js

A javascript library to run SQLite on the web.
http://sql.js.org
Other
12.68k stars 1.06k forks source link

StatementIterator leaks if not run to completion #457

Open rhashimoto opened 3 years ago

rhashimoto commented 3 years ago

A statement provided by StatementIterator can be leaked until the Database is closed if the iterator is not run to completion. A statement is not freed until next is called for the following iteration, which might not happen if, for example, a for...of loop is exited via break, return, or thrown exception.

Careful coding can work around this issue, but that code will also be uglier and harder to read. A better fix would be to implement the optional return method on the iterator to reclaim its resources, as that will be automatically called on early loop termination.

lovasoa commented 3 years ago

Good catch ! Are you interested in making a PR ?

rhashimoto commented 3 years ago

@lovasoa Honestly I find it difficult to work in the sql.js tree because the coding standard is ES5 and you have to run emcc for changes that only affect the Javascript side. If you can get someone to help improve the project infrastructure, it would be a lot easier to dash off a fix - I would do it even though I can't use it (I need an asynchronous API).