This won't work. As soon as you throw this back into Rubyland, you run the risk of Ruby keeping a reference to it for a looooong time, way after libgit2 has freed the underlying data structure. This will cause segfaults.