Fixing malloc() call => platform_malloc_shared(). Adding some memory checks