emnl/gnista — pull request #4 by nelgau (2014-03-26 02:24:07+00:00)
Title: Ensure the open member is initialized on exception

We've observed segfaults while attempting to open non-existent stores. Although the initializer of each class correctly throws `GnistaException`, raising this error skips the initialization of the `open` member on the `instance_logwriter`, `instance_logreader` and `instance_hashreader` structs. Depending on the contents of the allocated buffer, during deallocation, the value of that member may erroneously and nondeterministically evaluate to `true`, causing a segfault in, for example, `sparkey_hash_close `. This pull request reverses the order of `raise_sparkey` and the assignment, correcting the issue in our environment.

Here's a minimal test case that reliably reproduces the issue on Mac OS X Lion (10.8.4):

```ruby
require 'gnista'

begin
Gnista::Hash.new(rand.to_s, rand.to_s)
rescue GnistaException
end

GC.start
# => SEGFAULT!
```

/cc @jtai @spkrka