fixed memory leaks at the allocation of new chunks
fixed style