Free state hook slot only if slot exists.

Fixes assert on module unload.