fix memory allocations