memory: fix incorrect pointer comparison when freeing cuda memory