Fixing segmentation fault, holding reference to memory used by C until the end of the function.