Fix dns_qpmulti_memusage() on empty dns_qpmulti_t instance

The dns_qpmulti_memusage() causes assertion failure when called on
freshly created qpmulti instance because the qp->usage hasn't been
allocated yet.
This commit is contained in:
Ondřej Surý 2025-09-16 14:11:08 +02:00
parent 722ce92f10
commit b2f653b332
No known key found for this signature in database
GPG key ID: 2820F37E873DEA41
2 changed files with 15 additions and 1 deletions

View file

@ -1124,7 +1124,7 @@ dns_qpmulti_memusage(dns_qpmulti_t *multi) {
dns_qp_memusage_t memusage = dns_qp_memusage(qp);
if (qp->transaction_mode == QP_UPDATE) {
if (qp->transaction_mode == QP_UPDATE && qp->usage != NULL) {
memusage.bytes -= qp->usage[qp->bump].capacity;
memusage.bytes += qp->usage[qp->bump].used *
sizeof(dns_qpnode_t);

View file

@ -378,8 +378,22 @@ ISC_RUN_TEST_IMPL(qpmulti) {
isc_loopmgr_destroy();
}
ISC_RUN_TEST_IMPL(qpmulti_memusage) {
dns_qpmulti_t *qpm = NULL;
dns_qp_memusage_t mu;
dns_qpmulti_create(isc_g_mctx, &test_methods, NULL, &qpm);
mu = dns_qpmulti_memusage(qpm);
assert_int_equal(mu.leaves, 0);
assert_int_equal(mu.used, 0);
dns_qpmulti_destroy(&qpm);
}
ISC_TEST_LIST_START
ISC_TEST_ENTRY(qpmulti)
ISC_TEST_ENTRY(qpmulti_memusage)
ISC_TEST_LIST_END
ISC_TEST_MAIN