Fix memory leak with PGResult.

The postgres db result wasn't always deleted as it should. Fix this by
using shared_ptr with a custom Deleter.
Fix memory leak.

This doesn't really matter as the process is shut down anyway, but
having the leak messes with Valgrind.
Plus it's the right thing to do.