Fixed segfault, this is C code not C++