After freeing proc and sql, make sure to mark them as NULL so that the
event based code knows when they are safe to use.