Figured out the segfault problem. Wasn't allocating memory properly.