fix a memory leak in profiling, add a profiling test