fix memory allocation bugs on ARM