fix memory leak in QueryBuilder/JoinBuilder