4628. [bug] Fixed a potential reference leak in query_getdb(). [RT #45247] (cherry picked from commit 594eadcc)