fix memory leak in QueryBuilder/JoinBuilder
Merge pull request #5825 from joegreen0991/db-memory-leak-fix

Db memory leak fix #5568