Fixed a segfault issue with malloc