Skip to content

Commit

Permalink
freeing value gotten seems to reduce memleak
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Dec 24, 2009
1 parent 9361bd6 commit caaaa1f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/rufus/tokyo/cabinet/lib.rb
Expand Up @@ -66,6 +66,8 @@ class << self
#
attfunc :tcfree, [ :pointer ], :void

attfunc :free, [ :pointer ], :void

#
# tcadb functions
#
Expand Down
5 changes: 4 additions & 1 deletion lib/rufus/tokyo/cabinet/util.rb
Expand Up @@ -63,11 +63,14 @@ def outlen_op (method, *args)

return nil if out.address == 0

return out.get_bytes(0, outlen.get_int(0))
out.get_bytes(0, outlen.get_int(0))

ensure

outlen.free

#clib.free(out)
# uncommenting that wreaks havoc
end
end

Expand Down
6 changes: 5 additions & 1 deletion lib/rufus/tokyo/outlen.rb
Expand Up @@ -37,9 +37,13 @@ def outlen_op (method, *args)
out = lib.send(method, *args)

return nil if out.address == 0
return out.get_bytes(0, outlen.get_int(0))

out.get_bytes(0, outlen.get_int(0))

ensure
outlen.free
#lib.tcfree(out)
lib.free(out)
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/rufus/tokyo/tyrant/lib.rb
Expand Up @@ -54,6 +54,8 @@ class << self
alias :attfunc :attach_function
end

attfunc :free, [ :pointer ], :void

# http://1978th.net/tokyotyrant/spex.html#tcrdbapi

#
Expand Down
10 changes: 5 additions & 5 deletions spec/cabinet_btree_spec.rb
Expand Up @@ -31,7 +31,7 @@

@db.getdup('a').should.equal([ 'a0', 'a1' ])
end

it 'should be able to fetch keys for duplicate values' do
[ %w[John Hornbeck],
%w[Tim Gourley],
Expand All @@ -58,11 +58,11 @@
end

describe 'Rufus::Tokyo::Cabinet .tcb order' do

before do
FileUtils.rm(DB_FILE) if File.exist? DB_FILE
end

it 'should default to a lexical order' do

db = Rufus::Tokyo::Cabinet.new(DB_FILE)
Expand All @@ -85,8 +85,8 @@
db.close
end

#
#
# It's not possible to call tcbdbsetcmpfunc() through the abstract API, so
# changing comparison functions are only supported through the Edo interface.
#
#
end

0 comments on commit caaaa1f

Please sign in to comment.