Is the SQLite3 gem known to have memory corruption?

  • Thread starter Timothy J. Wood
  • Start date
T

Timothy J. Wood

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
 
T

Timothy J. Wood

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top