You should delete current
before you set it to NULL
, not afterwards. In fact, there is no reason to set current
to NULL
in the first place: the pointer current
is passed by value, so updating it has no external effect.
Note that it is legal to delete NULL
, but it is a no-op.