diff --git a/CHANGES b/CHANGES index 36f6d0ec72..c4043a9e2d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +4628. [bug] Fixed a potential reference leak in query_getdb(). + [RT #45247] + 4626. [test] Added more tests for handling of different record ordering in CNAME and DNAME responses. [QA #430] diff --git a/bin/named/query.c b/bin/named/query.c index d6cc87d68d..cbaf648dd5 100644 --- a/bin/named/query.c +++ b/bin/named/query.c @@ -721,7 +721,7 @@ ns_query_init(ns_client_t *client) { return (result); } -static inline ns_dbversion_t * +static ns_dbversion_t * query_findversion(ns_client_t *client, dns_db_t *db) { ns_dbversion_t *dbversion; @@ -1223,6 +1223,8 @@ query_getdb(ns_client_t *client, dns_name_t *name, dns_rdatatype_t qtype, zonelabels, &cm, &ci, &tdbp); /* If we successful, we found a better match. */ if (tresult == ISC_R_SUCCESS) { + ns_dbversion_t *dbversion; + /* * If the previous search returned a zone, detach it. */ @@ -1241,15 +1243,16 @@ query_getdb(ns_client_t *client, dns_name_t *name, dns_rdatatype_t qtype, */ *versionp = NULL; - /* - * Get our database version. - */ - dns_db_currentversion(tdbp, versionp); - - /* - * Be sure to return our database. - */ - *dbp = tdbp; + dbversion = query_findversion(client, tdbp); + if (dbversion == NULL) { + result = ISC_R_NOMEMORY; + } else { + /* + * Be sure to return our database. + */ + *dbp = tdbp; + *versionp = dbversion->version; + } /* * We return a null zone, No stats for DLZ zones.