From: Ondřej Surý Date: Tue, 11 May 2021 12:37:18 +0000 (+0200) Subject: Replace isc_mem_allocate() usage with isc_mem_get() in netmgr.c X-Git-Tag: v9.17.17~40^2~19 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=5ab05d1696561c8169367ebd3805bd4094c24982;p=thirdparty%2Fbind9.git Replace isc_mem_allocate() usage with isc_mem_get() in netmgr.c The isc_mem_allocate() comes with additional cost because of the memory tracking. In this commit, we replace the usage with isc_mem_get() because we track the allocated sizes anyway, so it's possible to also replace isc_mem_free() with isc_mem_put(). --- diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 877fd6d6645..6f2d05c74c2 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -1261,7 +1261,7 @@ nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree FLARG) { } if (sock->buf != NULL) { - isc_mem_free(sock->mgr->mctx, sock->buf); + isc_mem_put(sock->mgr->mctx, sock->buf, sock->buf_size); } if (sock->quota != NULL) { @@ -1279,8 +1279,10 @@ nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree FLARG) { isc_astack_destroy(sock->inactivereqs); sock->magic = 0; - isc_mem_free(sock->mgr->mctx, sock->ah_frees); - isc_mem_free(sock->mgr->mctx, sock->ah_handles); + isc_mem_put(sock->mgr->mctx, sock->ah_frees, + sock->ah_size * sizeof(sock->ah_frees[0])); + isc_mem_put(sock->mgr->mctx, sock->ah_handles, + sock->ah_size * sizeof(sock->ah_handles[0])); isc_mutex_destroy(&sock->lock); isc_condition_destroy(&sock->scond); #if HAVE_LIBNGHTTP2 @@ -1492,10 +1494,10 @@ isc___nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type, isc_nm_attach(mgr, &sock->mgr); sock->uv_handle.handle.data = sock; - sock->ah_frees = isc_mem_allocate(mgr->mctx, - sock->ah_size * sizeof(size_t)); - sock->ah_handles = isc_mem_allocate( - mgr->mctx, sock->ah_size * sizeof(isc_nmhandle_t *)); + sock->ah_frees = isc_mem_get(mgr->mctx, + sock->ah_size * sizeof(sock->ah_frees[0])); + sock->ah_handles = isc_mem_get( + mgr->mctx, sock->ah_size * sizeof(sock->ah_handles[0])); ISC_LINK_INIT(&sock->quotacb, link); for (size_t i = 0; i < 32; i++) { sock->ah_frees[i] = i; @@ -1905,12 +1907,12 @@ isc__nm_alloc_dnsbuf(isc_nmsocket_t *sock, size_t len) { if (sock->buf == NULL) { /* We don't have the buffer at all */ size_t alloc_len = len < NM_REG_BUF ? NM_REG_BUF : NM_BIG_BUF; - sock->buf = isc_mem_allocate(sock->mgr->mctx, alloc_len); + sock->buf = isc_mem_get(sock->mgr->mctx, alloc_len); sock->buf_size = alloc_len; } else { /* We have the buffer but it's too small */ - sock->buf = isc_mem_reallocate(sock->mgr->mctx, sock->buf, - NM_BIG_BUF); + isc_mem_put(sock->mgr->mctx, sock->buf, sock->buf_size); + sock->buf = isc_mem_get(sock->mgr->mctx, NM_BIG_BUF); sock->buf_size = NM_BIG_BUF; } }