This "fixes" the segfault in the test program, but it seems like there must be another underlying problem.