Fix a memory leak when querying tables

The tightdb::Query object was never being deleted, and fortunately doesn't even need to be heap-allocated.

The test is a little fiddly due to trying to avoid false-positives and taking forever to run while still catching the leak.

@alazier 
Please put a comment here to explain what we are testing.