Forum: Ruby Is the SQLite3 gem known to have memory corruption?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9d9d4c769b20cd12b15f4e5b991b4ca5?d=identicon&s=25 Timothy J. Wood (Guest)
on 2006-02-05 18:51
(Received via mailing list)
Running the following produces bizarre results (trimmed down from
an actual app):

-----
#!/opt/local/bin/ruby

require 'rubygems'
require_gem 'sqlite3-ruby'

def each_batch(size=1)
   until false
     batch = []
     (1..20).each {|i| batch << "x"}
     yield batch
   end
end

database = SQLite3::Database.new("/tmp/test.db")
counter = 0
each_batch {|batch|
   database.transaction {
     counter += batch.length
     print "OK\n"
   }
}
-----

   For a while it prints "OK", but then eventually:

./test_bad_batch.rb:20: undefined method `length' for 4085314:Fixnum
(NoMethodError)
         from /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/
lib/sqlite3/database.rb:593:in `transaction'
         from ./test_bad_batch.rb:19
         from ./test_bad_batch.rb:11:in `each_batch'
         from ./test_bad_batch.rb:11:in `each_batch'
         from ./test_bad_batch.rb:18


   That is the 'batch' is getting yielded as random pointer instead
of the array generated inside each_batch!

   I've tried narrowing this further (particularly getting rid of
SQLite usage), but this is the simplest case I can come up with so far.

   I'm running on Mac OS X 10.4.4 with ruby 1.8.4 installed via
Darwin Ports (as well as rubygems installed from there and then
sqlite3 installed via that copy of gems).

----
% /opt/local/bin/ruby -v
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.3.0]

% /opt/local/bin/gem list sqlite3-ruby

*** LOCAL GEMS ***

sqlite3-ruby (1.1.0)
     SQLite3/Ruby is a module to allow Ruby scripts to interface with a
     SQLite3 database.
----

   I've tried both the system supplied sqlite (v3.1.3) and the latest
version (installed via Darwin Ports), 3.3.3.

   Any info would be helpful!

-tim
934180817a3765d132193a5428f99051?d=identicon&s=25 Sylvain Joyeux (Guest)
on 2006-02-05 19:42
(Received via mailing list)
>    Any info would be helpful!
See
http://rubyforge.org/tracker/index.php?func=detail...
and the patch I submitted, which should fix the problem
http://rubyforge.org/tracker/index.php?func=detail...

Regards,
Sylvain
9d9d4c769b20cd12b15f4e5b991b4ca5?d=identicon&s=25 Timothy J. Wood (Guest)
on 2006-02-05 20:13
(Received via mailing list)
Thanks; I've applied this patch in my /opt/local/lib/ruby/gems/1.8/
gems/sqlite3-ruby-1.1.0

   It isn't clear to me how to get the native code re-applied to the
gem.  After patching sqlite3_api.i, I did:

% sudo ruby extconf.rb install sqlite3-ruby

   but just reported there being nothing to do and re-running the
test case yielded the same problem.

   I'm sorry if this is a basic question, but I'm new to patching
ruby itself.  Any idea from the sqlite3 gem provider when this patch
might be included?

-tim
9d9d4c769b20cd12b15f4e5b991b4ca5?d=identicon&s=25 Timothy J. Wood (Guest)
on 2006-02-06 18:24
(Received via mailing list)
Thanks; this patch did in fact fix my issue.  Of course, it took
me a while to figure out that I needed swig installed to get your
patch to do anything.  Luckily I noticed the SWIG bug in the tracker :)

-tim
This topic is locked and can not be replied to.