Fix memory leak in groupby and add tests for leaks to test harness.