The root of the segfault was hard to track down (gdb was giving me false clues, even).