1
0
mirror of https://gitlab.isc.org/isc-projects/bind9.git synced 2025-04-18 09:44:09 +03:00

Replace isc_mem_destroy() with isc_mem_detach()

Remove legacy isc_mem_destroy() and just use isc_mem_detach() as
isc_mem_destroy() doesn't play well with call_rcu API.
This commit is contained in:
Ondřej Surý 2024-09-09 13:38:31 +02:00
parent f28020265c
commit 552cf64a70
No known key found for this signature in database
GPG Key ID: 2820F37E873DEA41
34 changed files with 37 additions and 78 deletions

View File

@ -761,7 +761,7 @@ cleanup:
}
if (mctx != NULL) {
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
}
return result == ISC_R_SUCCESS ? 0 : 1;

View File

@ -577,7 +577,7 @@ main(int argc, char **argv) {
fprintf(errout, "OK\n");
}
destroy();
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return (result == ISC_R_SUCCESS) ? 0 : 1;
}

View File

@ -290,7 +290,7 @@ options {\n\
isc_mem_stats(mctx, stderr);
}
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return 0;
}

View File

@ -296,7 +296,7 @@ nsupdate -k <keyfile>\n");
isc_mem_stats(mctx, stderr);
}
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return 0;
}

View File

@ -1075,7 +1075,7 @@ cleanup(void) {
if (print_mem_stats && verbose > 10) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
}
}

View File

@ -543,7 +543,7 @@ main(int argc, char **argv) {
if (verbose > 10) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
fflush(stdout);
if (ferror(stdout)) {

View File

@ -456,7 +456,7 @@ main(int argc, char **argv) {
if (verbose > 10) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
fflush(stdout);
if (ferror(stdout)) {

View File

@ -746,7 +746,7 @@ main(int argc, char **argv) {
isc_mem_stats(mctx, stdout);
}
isc_mem_free(mctx, label);
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
if (freeit != NULL) {
free(freeit);

View File

@ -1280,7 +1280,7 @@ main(int argc, char **argv) {
if (verbose > 10) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
if (freeit != NULL) {
free(freeit);

View File

@ -248,7 +248,7 @@ cleanup:
if (dir != NULL) {
isc_mem_free(mctx, dir);
}
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return 0;
}

View File

@ -949,7 +949,7 @@ main(int argc, char **argv) {
isc_mem_stats(mctx, stdout);
}
isc_mem_free(mctx, directory);
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return 0;
}

View File

@ -330,7 +330,7 @@ main(int argc, char *argv[]) {
if (verbose > 10) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return result == ISC_R_SUCCESS ? 0 : 1;
}

View File

@ -111,7 +111,7 @@ cleanup:
}
if (mctx != NULL) {
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
}
return result != ISC_R_SUCCESS ? 1 : 0;

View File

@ -140,7 +140,7 @@ main(int argc, char **argv) {
printf("%s\n", filename);
dst_key_free(&key);
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return 0;
}

View File

@ -260,7 +260,7 @@ main(int argc, char *argv[]) {
if (printmemstats) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return 0;
}

View File

@ -425,7 +425,7 @@ cleanup:
if (message != NULL) {
dns_message_detach(&message);
}
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
exit(rv);
}

View File

@ -61,7 +61,7 @@ cleanup(void) {
isc_lex_destroy(&lex);
}
if (mctx != NULL) {
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
}
}

View File

@ -154,7 +154,7 @@ main(int argc, char **argv) {
if (memstats) {
isc_mem_stats(mctx, stderr);
}
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
fflush(stdout);
if (ferror(stdout)) {

View File

@ -74,6 +74,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
end:
dns_db_detach(&db);
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return 0;
}

View File

@ -211,7 +211,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
}
dns_qp_destroy(&qp);
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
isc_mem_checkdestroyed(stderr);
for (size_t i = 0; i < ARRAY_SIZE(item); i++) {

View File

@ -145,6 +145,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
cleanup:
isc_lex_close(lex);
isc_lex_destroy(&lex);
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return 0;
}

View File

@ -226,7 +226,7 @@ dst__lib_shutdown(void) {
}
}
isc_mem_destroy(&dst__mctx);
isc_mem_detach(&dst__mctx);
}
bool

View File

@ -314,5 +314,5 @@ isc__crypto_shutdown(void) {
OPENSSL_cleanup();
isc_mem_destroy(&isc__crypto_mctx);
isc_mem_detach(&isc__crypto_mctx);
}

View File

@ -272,13 +272,6 @@ isc__mem_detach(isc_mem_t **_ISC_MEM_FLARG);
*/
/*@}*/
#define isc_mem_destroy(cp) isc__mem_destroy((cp)_ISC_MEM_FILELINE)
void
isc__mem_destroy(isc_mem_t **_ISC_MEM_FLARG);
/*%<
* Destroy a memory context.
*/
void
isc_mem_stats(isc_mem_t *mctx, FILE *out);
/*%<

View File

@ -47,5 +47,5 @@ isc_managers_destroy(isc_mem_t **mctxp, isc_loopmgr_t **loopmgrp,
isc_netmgr_destroy(netmgrp);
isc_loopmgr_destroy(loopmgrp);
isc_mem_destroy(mctxp);
isc_mem_detach(mctxp);
}

View File

@ -598,40 +598,6 @@ isc__mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size,
isc__mem_detach(&ctx FLARG_PASS);
}
void
isc__mem_destroy(isc_mem_t **ctxp FLARG) {
isc_mem_t *ctx = NULL;
/*
* This routine provides legacy support for callers who use mctxs
* without attaching/detaching.
*/
REQUIRE(ctxp != NULL && VALID_CONTEXT(*ctxp));
ctx = *ctxp;
*ctxp = NULL;
rcu_barrier();
#if ISC_MEM_TRACKLINES
if ((ctx->debugging & ISC_MEM_DEBUGTRACE) != 0) {
fprintf(stderr, "destroy mctx %p file %s line %u\n", ctx, file,
line);
}
if (isc_refcount_decrement(&ctx->references) > 1) {
print_active(ctx, stderr);
}
#else /* if ISC_MEM_TRACKLINES */
isc_refcount_decrementz(&ctx->references);
#endif /* if ISC_MEM_TRACKLINES */
isc_refcount_destroy(&ctx->references);
destroy(ctx);
*ctxp = NULL;
}
void *
isc__mem_get(isc_mem_t *ctx, size_t size, int flags FLARG) {
void *ptr = NULL;

View File

@ -146,7 +146,7 @@ void
isc__uv_shutdown(void) {
#if UV_VERSION_HEX >= UV_VERSION(1, 38, 0)
uv_library_shutdown();
isc_mem_destroy(&isc__uv_mctx);
isc_mem_detach(&isc__uv_mctx);
#endif /* UV_VERSION_HEX < UV_VERSION(1, 38, 0) */
}

View File

@ -64,7 +64,7 @@ void
isc__xml_shutdown(void) {
#ifdef HAVE_LIBXML2
xmlCleanupParser();
isc_mem_destroy(&isc__xml_mctx);
isc_mem_detach(&isc__xml_mctx);
#endif /* HAVE_LIBXML2 */
}

View File

@ -100,7 +100,7 @@ main(void) {
printf("names %u\n", count);
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return 0;
}

View File

@ -889,7 +889,7 @@ main(void) {
isc_mem_free(mctx, item);
isc_mem_checkdestroyed(stdout);
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return 0;
}

View File

@ -158,7 +158,7 @@ ISC_LOOP_TEST_IMPL(overmempurge_bigrdata) {
}
dns_db_detach(&db);
isc_mem_destroy(&mctx2);
isc_mem_detach(&mctx2);
isc_loopmgr_shutdown(loopmgr);
}
@ -208,7 +208,7 @@ ISC_LOOP_TEST_IMPL(overmempurge_longname) {
}
dns_db_detach(&db);
isc_mem_destroy(&mctx2);
isc_mem_detach(&mctx2);
isc_loopmgr_shutdown(loopmgr);
}

View File

@ -249,7 +249,7 @@ teardown_managers(void **state);
r = cmocka_run_group_tests(tests, setup, teardown); \
} \
\
isc_mem_destroy(&mctx); \
isc_mem_detach(&mctx); \
\
return (r); \
}

View File

@ -197,7 +197,7 @@ ISC_RUN_TEST_IMPL(isc_mem_inuse) {
assert_int_equal(diff, 0);
isc_mem_destroy(&mctx2);
isc_mem_detach(&mctx2);
}
ISC_RUN_TEST_IMPL(isc_mem_zeroget) {
@ -323,7 +323,7 @@ ISC_RUN_TEST_IMPL(isc_mem_overmem) {
isc_mem_free(omctx, data1);
assert_false(isc_mem_isovermem(omctx));
isc_mem_destroy(&omctx);
isc_mem_detach(&omctx);
}
#if ISC_MEM_TRACKLINES
@ -345,7 +345,7 @@ ISC_RUN_TEST_IMPL(isc_mem_noflags) {
assert_non_null(ptr);
isc__mem_printactive(mctx2, f);
isc_mem_put(mctx2, ptr, 2048);
isc_mem_destroy(&mctx2);
isc_mem_detach(&mctx2);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
isc_stdio_close(f);
@ -379,7 +379,7 @@ ISC_RUN_TEST_IMPL(isc_mem_recordflag) {
assert_non_null(ptr);
isc__mem_printactive(mctx2, f);
isc_mem_put(mctx2, ptr, 2048);
isc_mem_destroy(&mctx2);
isc_mem_detach(&mctx2);
isc_stdio_close(f);
memset(buf, 0, sizeof(buf));
@ -419,7 +419,7 @@ ISC_RUN_TEST_IMPL(isc_mem_traceflag) {
assert_non_null(ptr);
isc__mem_printactive(mctx2, f);
isc_mem_put(mctx2, ptr, 2048);
isc_mem_destroy(&mctx2);
isc_mem_detach(&mctx2);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
isc_stdio_close(f);

View File

@ -79,7 +79,7 @@ setup_mctx(void **state ISC_ATTR_UNUSED) {
int
teardown_mctx(void **state ISC_ATTR_UNUSED) {
isc_mem_destroy(&mctx);
isc_mem_detach(&mctx);
return 0;
}