fix device memory leaks