File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 66
77VALUE cSqlite3Statement ;
88
9+ static void
10+ statement_deallocate (void * data )
11+ {
12+ sqlite3StmtRubyPtr s = (sqlite3StmtRubyPtr )data ;
13+
14+ if (s -> st ) {
15+ sqlite3_finalize (s -> st );
16+ }
17+
18+ xfree (data );
19+ }
20+
921static size_t
1022statement_memsize (const void * data )
1123{
@@ -18,7 +30,7 @@ static const rb_data_type_t statement_type = {
1830 "SQLite3::Backup" ,
1931 {
2032 NULL ,
21- RUBY_TYPED_DEFAULT_FREE ,
33+ statement_deallocate ,
2234 statement_memsize ,
2335 },
2436 0 ,
Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ Gem::Specification.new do |s|
8989 "test/test_integration_resultset.rb" ,
9090 "test/test_integration_statement.rb" ,
9191 "test/test_pragmas.rb" ,
92+ "test/test_resource_cleanup.rb" ,
9293 "test/test_result_set.rb" ,
9394 "test/test_sqlite3.rb" ,
9495 "test/test_statement.rb" ,
Original file line number Diff line number Diff line change 1+ require "helper"
2+
3+ module SQLite3
4+ # these tests will cause ruby_memcheck to report a leak if we're not cleaning up resources
5+ class TestResourceCleanup < SQLite3 ::TestCase
6+ def test_cleanup_unclosed_database_object
7+ 100 . times do
8+ SQLite3 ::Database . new ( ':memory:' )
9+ end
10+ end
11+
12+ def test_cleanup_unclosed_statement_object
13+ 100 . times do
14+ db = SQLite3 ::Database . new ( ':memory:' )
15+ db . execute ( 'create table foo(text BLOB)' )
16+ db . prepare ( 'select * from foo' )
17+ end
18+ end
19+
20+ # def test_cleanup_unclosed_resultset_object
21+ # db = SQLite3::Database.new(':memory:')
22+ # db.execute('create table foo(text BLOB)')
23+ # stmt = db.prepare('select * from foo')
24+ # stmt.execute
25+ # end
26+ end
27+ end
You can’t perform that action at this time.
0 commit comments