Simplify query_getcachedb()

Modify query_getcachedb() so that it uses a common return path for both
success and failure.  Remove a redundant NULL check since 'db' will
never be NULL after being passed as a target pointer to dns_db_attach().
Fix coding style issues.
This commit is contained in:
Michał Kępień 2018-06-28 13:38:39 +02:00
parent e9f17da6e9
commit cde16236fb

View file

@ -1439,6 +1439,10 @@ rpz_getdb(ns_client_t *client, dns_name_t *p_name, dns_rpz_type_t rpz_type,
return (result);
}
/*%
* Find a cache database to answer the query. This may fail with DNS_R_REFUSED
* if the client is not allowed to use the cache.
*/
static inline isc_result_t
query_getcachedb(ns_client_t *client, const dns_name_t *name,
dns_rdatatype_t qtype, dns_db_t **dbp, unsigned int options)
@ -1448,32 +1452,23 @@ query_getcachedb(ns_client_t *client, const dns_name_t *name,
REQUIRE(dbp != NULL && *dbp == NULL);
/*%
* Find a cache database to answer the query.
* This may fail with DNS_R_REFUSED if the client
* is not allowed to use the cache.
*/
if (!USECACHE(client))
if (!USECACHE(client)) {
return (DNS_R_REFUSED);
}
dns_db_attach(client->view->cachedb, &db);
result = query_checkcacheaccess(client, name, qtype, options);
if (result != ISC_R_SUCCESS) {
goto refuse;
dns_db_detach(&db);
}
/* Transfer ownership. */
/*
* If query_checkcacheaccess() succeeded, transfer ownership of 'db'.
* Otherwise, 'db' will be NULL due to the dns_db_detach() call above.
*/
*dbp = db;
return (ISC_R_SUCCESS);
refuse:
result = DNS_R_REFUSED;
if (db != NULL)
dns_db_detach(&db);
return (result);
}