Fortran deallocates automatically only allocatable objects, not pointers. So, if C has been allocated, then nullify(C) is not enough. You must first deallocate each sub-pointer (if allocated) and then deallocate C at the end of the process to free the memory.
@harphool it is usually better to allocate only allocatable objects even if pointer objects may be allocated too. I prefer to use pointers only to point to a memory already allocated.
François Jacq