Fix performance problem in has_free_var. Add new test at src/tests/kernel/free_vars.cpp that exposes the problem.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>