Covers allocation checks, cleanup and pointer resetting.