From: Evan Hunt Date: Wed, 28 May 2025 06:04:33 +0000 (-0700) Subject: simplify code around isc_mem_put() and isc_mem_free() X-Git-Tag: v9.21.9~30^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd9a685f4a7d3ff9192c8ef1f843c31e19451374;p=thirdparty%2Fbind9.git simplify code around isc_mem_put() and isc_mem_free() it isn't necessary to set a pointer to NULL after calling isc_mem_put() or isc_mem_free(), because those macros take care of it automatically. --- diff --git a/bin/dnssec/dnssec-revoke.c b/bin/dnssec/dnssec-revoke.c index 8c647fefd62..9dbbb3cf84d 100644 --- a/bin/dnssec/dnssec-revoke.c +++ b/bin/dnssec/dnssec-revoke.c @@ -155,7 +155,6 @@ main(int argc, char **argv) { } if (strcmp(dir, ".") == 0) { isc_mem_free(mctx, dir); - dir = NULL; } } diff --git a/bin/named/config.c b/bin/named/config.c index e23f95111f4..babf61ad8f1 100644 --- a/bin/named/config.c +++ b/bin/named/config.c @@ -560,7 +560,6 @@ named_config_getname(isc_mem_t *mctx, const cfg_obj_t *obj, 0); if (result != ISC_R_SUCCESS) { isc_mem_put(mctx, *namep, sizeof(**namep)); - *namep = NULL; return result; } dns_name_dup(dns_fixedname_name(&fname), mctx, *namep); diff --git a/bin/named/server.c b/bin/named/server.c index 756ea9a0c68..9d7d0e0c550 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -7059,7 +7059,6 @@ cleanup_session_key(named_server_t *server, isc_mem_t *mctx) { if (server->session_keyfile != NULL) { isc_file_remove(server->session_keyfile); isc_mem_free(mctx, server->session_keyfile); - server->session_keyfile = NULL; } if (server->session_keyname != NULL) { @@ -7067,7 +7066,6 @@ cleanup_session_key(named_server_t *server, isc_mem_t *mctx) { dns_name_free(server->session_keyname, mctx); } isc_mem_put(mctx, server->session_keyname, sizeof(dns_name_t)); - server->session_keyname = NULL; } if (server->sessionkey != NULL) { diff --git a/bin/named/tsigconf.c b/bin/named/tsigconf.c index 564e1ca0876..fd6e94c0c2f 100644 --- a/bin/named/tsigconf.c +++ b/bin/named/tsigconf.c @@ -101,7 +101,6 @@ add_initial_keys(const cfg_obj_t *list, dns_tsigkeyring_t *ring, ret = dns_tsigkey_create(keyname, alg, secret, secretlen, mctx, &tsigkey); isc_mem_put(mctx, secret, secretalloc); - secret = NULL; if (ret == ISC_R_SUCCESS) { ret = dns_tsigkeyring_add(ring, tsigkey); } diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index 3c8e8578215..ee282271151 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -1795,7 +1795,6 @@ evaluate_realm(char *cmdline) { if (realm != NULL) { isc_mem_free(gmctx, realm); - realm = NULL; } word = nsu_strsep(&cmdline, " \t\r\n"); @@ -2722,7 +2721,6 @@ recvsoa(void *arg) { } isc_mem_put(gmctx, reqinfo, sizeof(nsu_requestinfo_t)); - reqinfo = NULL; ddebug("About to create rcvmsg"); dns_message_create(gmctx, NULL, NULL, DNS_MESSAGE_INTENTPARSE, &rcvmsg); @@ -3455,11 +3453,9 @@ cleanup(void) { #ifdef HAVE_GSSAPI if (kserver != NULL) { isc_mem_put(gmctx, kserver, sizeof(isc_sockaddr_t)); - kserver = NULL; } if (realm != NULL) { isc_mem_free(gmctx, realm); - realm = NULL; } if (dns_name_dynamic(&tmpzonename)) { dns_name_free(&tmpzonename, gmctx); diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index a9d0975efd8..24ef6e9cdc7 100644 --- a/bin/tools/mdig.c +++ b/bin/tools/mdig.c @@ -1487,7 +1487,6 @@ plus_option(char *option, struct query *query, bool global) { if (!state) { if (query->ecs_addr != NULL) { isc_mem_free(mctx, query->ecs_addr); - query->ecs_addr = NULL; } break; } @@ -2169,7 +2168,6 @@ main(int argc, char *argv[]) { } if (query->ecs_addr != NULL) { isc_mem_free(mctx, query->ecs_addr); - query->ecs_addr = NULL; } isc_mem_free(mctx, query); } diff --git a/lib/dns/adb.c b/lib/dns/adb.c index d95ae44bd1d..ef37c987db8 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -3137,7 +3137,6 @@ dns_adb_setcookie(dns_adb_t *adb, dns_adbaddrinfo_t *addr, (cookie == NULL || len != entry->cookielen)) { isc_mem_put(adb->mctx, entry->cookie, entry->cookielen); - entry->cookie = NULL; entry->cookielen = 0; } diff --git a/lib/dns/catz.c b/lib/dns/catz.c index 6a83146f26f..638c90dbe79 100644 --- a/lib/dns/catz.c +++ b/lib/dns/catz.c @@ -174,7 +174,6 @@ dns_catz_options_free(dns_catz_options_t *options, isc_mem_t *mctx) { } if (options->zonedir != NULL) { isc_mem_free(mctx, options->zonedir); - options->zonedir = NULL; } if (options->allow_query != NULL) { isc_buffer_free(&options->allow_query); @@ -200,7 +199,6 @@ dns_catz_options_copy(isc_mem_t *mctx, const dns_catz_options_t *src, if (dst->zonedir != NULL) { isc_mem_free(mctx, dst->zonedir); - dst->zonedir = NULL; } if (src->zonedir != NULL) { diff --git a/lib/dns/keytable.c b/lib/dns/keytable.c index 15c204f08a2..2caae9612c7 100644 --- a/lib/dns/keytable.c +++ b/lib/dns/keytable.c @@ -111,7 +111,6 @@ destroy_keynode(dns_keynode_t *knode) { } isc_mem_put(knode->mctx, knode->dslist, sizeof(*knode->dslist)); - knode->dslist = NULL; } dns_name_free(&knode->name, knode->mctx); diff --git a/lib/dns/message.c b/lib/dns/message.c index b387dc11f2f..2c441544064 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -2502,7 +2502,6 @@ dns_message_puttemprdataset(dns_message_t *msg, dns_rdataset_t **item) { REQUIRE(!dns_rdataset_isassociated(*item)); isc_mempool_put(msg->rdspool, *item); - *item = NULL; } void diff --git a/lib/dns/remote.c b/lib/dns/remote.c index e1e50d58e4e..2ce059dccfd 100644 --- a/lib/dns/remote.c +++ b/lib/dns/remote.c @@ -200,19 +200,16 @@ dns_remote_clear(dns_remote_t *remote) { if (remote->ok != NULL) { isc_mem_cput(mctx, remote->ok, count, sizeof(bool)); - remote->ok = NULL; } if (remote->addresses != NULL) { isc_mem_cput(mctx, remote->addresses, count, sizeof(isc_sockaddr_t)); - remote->addresses = NULL; } if (remote->sources != NULL) { isc_mem_cput(mctx, remote->sources, count, sizeof(isc_sockaddr_t)); - remote->sources = NULL; } if (remote->keynames != NULL) { @@ -222,12 +219,10 @@ dns_remote_clear(dns_remote_t *remote) { dns_name_free(remote->keynames[i], mctx); isc_mem_put(mctx, remote->keynames[i], sizeof(dns_name_t)); - remote->keynames[i] = NULL; } } isc_mem_cput(mctx, remote->keynames, count, sizeof(dns_name_t *)); - remote->keynames = NULL; } if (remote->tlsnames != NULL) { @@ -237,12 +232,10 @@ dns_remote_clear(dns_remote_t *remote) { dns_name_free(remote->tlsnames[i], mctx); isc_mem_put(mctx, remote->tlsnames[i], sizeof(dns_name_t)); - remote->tlsnames[i] = NULL; } } isc_mem_cput(mctx, remote->tlsnames, count, sizeof(dns_name_t *)); - remote->tlsnames = NULL; } remote->curraddr = 0; diff --git a/lib/dns/resconf.c b/lib/dns/resconf.c index 00df0094a80..0b7c3eb151e 100644 --- a/lib/dns/resconf.c +++ b/lib/dns/resconf.c @@ -386,7 +386,6 @@ resconf_parsesearch(irs_resconf_t *conf, FILE *fp) { * Search and domain are mutually exclusive. */ isc_mem_free(conf->mctx, conf->domainname); - conf->domainname = NULL; } /* diff --git a/lib/dns/tsig.c b/lib/dns/tsig.c index 376bde418f0..211cba9dd8f 100644 --- a/lib/dns/tsig.c +++ b/lib/dns/tsig.c @@ -785,7 +785,6 @@ dns_tsig_sign(dns_message_t *msg) { if (tsig.signature != NULL) { isc_mem_put(mctx, tsig.signature, sigsize); - tsig.signature = NULL; } dns_message_gettempname(msg, &owner); diff --git a/lib/dns/view.c b/lib/dns/view.c index 489fc70a1b6..0cdf603db36 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -337,11 +337,9 @@ destroy(dns_view_t *view) { dns_view_setnewzones(view, false, NULL, NULL, 0ULL); if (view->new_zone_file != NULL) { isc_mem_free(view->mctx, view->new_zone_file); - view->new_zone_file = NULL; } if (view->new_zone_dir != NULL) { isc_mem_free(view->mctx, view->new_zone_dir); - view->new_zone_dir = NULL; } #ifdef HAVE_LMDB if (view->new_zone_dbenv != NULL) { @@ -350,7 +348,6 @@ destroy(dns_view_t *view) { } if (view->new_zone_db != NULL) { isc_mem_free(view->mctx, view->new_zone_db); - view->new_zone_db = NULL; } #endif /* HAVE_LMDB */ dns_fwdtable_destroy(&view->fwdtable); @@ -1741,7 +1738,6 @@ dns_view_setnewzones(dns_view_t *view, bool allow, void *cfgctx, if (view->new_zone_file != NULL) { isc_mem_free(view->mctx, view->new_zone_file); - view->new_zone_file = NULL; } #ifdef HAVE_LMDB @@ -1752,7 +1748,6 @@ dns_view_setnewzones(dns_view_t *view, bool allow, void *cfgctx, if (view->new_zone_db != NULL) { isc_mem_free(view->mctx, view->new_zone_db); - view->new_zone_db = NULL; } #endif /* HAVE_LMDB */ @@ -1815,13 +1810,11 @@ cleanup: if (result != ISC_R_SUCCESS) { if (view->new_zone_file != NULL) { isc_mem_free(view->mctx, view->new_zone_file); - view->new_zone_file = NULL; } #ifdef HAVE_LMDB if (view->new_zone_db != NULL) { isc_mem_free(view->mctx, view->new_zone_db); - view->new_zone_db = NULL; } if (env != NULL) { mdb_env_close(env); @@ -1840,7 +1833,6 @@ dns_view_setnewzonedir(dns_view_t *view, const char *dir) { if (view->new_zone_dir != NULL) { isc_mem_free(view->mctx, view->new_zone_dir); - view->new_zone_dir = NULL; } if (dir == NULL) { diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 1ee46b7565c..cecad687253 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -1289,11 +1289,9 @@ zone_free(dns_zone_t *zone) { if (zone->masterfile != NULL) { isc_mem_free(zone->mctx, zone->masterfile); } - zone->masterfile = NULL; if (zone->keydirectory != NULL) { isc_mem_free(zone->mctx, zone->keydirectory); } - zone->keydirectory = NULL; if (zone->kasp != NULL) { dns_kasp_detach(&zone->kasp); } @@ -1315,7 +1313,6 @@ zone_free(dns_zone_t *zone) { if (zone->journal != NULL) { isc_mem_free(zone->mctx, zone->journal); } - zone->journal = NULL; if (zone->stats != NULL) { isc_stats_detach(&zone->stats); } @@ -12012,7 +12009,6 @@ fail: } if (masterfile != NULL) { isc_mem_free(zone->mctx, masterfile); - masterfile = NULL; } if (result == DNS_R_CONTINUE) { diff --git a/lib/isc/log.c b/lib/isc/log.c index b27049f5616..6ffd454750c 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -444,7 +444,6 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) { if (lcfg->tag != NULL) { isc_mem_free(lcfg->lctx->mctx, lcfg->tag); } - lcfg->tag = NULL; lcfg->highest_level = 0; lcfg->magic = 0; @@ -679,7 +678,6 @@ isc_log_settag(isc_logconfig_t *lcfg, const char *tag) { if (lcfg->tag != NULL) { isc_mem_free(lcfg->lctx->mctx, lcfg->tag); } - lcfg->tag = NULL; } } diff --git a/lib/isc/netmgr/http.c b/lib/isc/netmgr/http.c index 7e138332eeb..3a6ba669212 100644 --- a/lib/isc/netmgr/http.c +++ b/lib/isc/netmgr/http.c @@ -531,7 +531,6 @@ put_http_cstream(isc_mem_t *mctx, http_cstream_t *stream) { isc_mem_free(mctx, stream->uri); if (stream->GET_path != NULL) { isc_mem_free(mctx, stream->GET_path); - stream->GET_path = NULL; stream->GET_path_len = 0; } @@ -2181,7 +2180,6 @@ server_handle_path_header(isc_nmsocket_t *socket, const uint8_t *value, if (!isc_nm_http_path_isvalid(socket->h2->request_path)) { isc_mem_free(socket->worker->mctx, socket->h2->request_path); - socket->h2->request_path = NULL; return ISC_HTTP_ERROR_BAD_REQUEST; } @@ -2192,7 +2190,6 @@ server_handle_path_header(isc_nmsocket_t *socket, const uint8_t *value, socket->h2->cbarg = handler->cbarg; } else { isc_mem_free(socket->worker->mctx, socket->h2->request_path); - socket->h2->request_path = NULL; return ISC_HTTP_ERROR_NOT_FOUND; } @@ -3648,12 +3645,10 @@ isc__nm_http_cleanup_data(isc_nmsocket_t *sock) { if (sock->h2->request_path != NULL) { isc_mem_free(sock->worker->mctx, sock->h2->request_path); - sock->h2->request_path = NULL; } if (sock->h2->query_data != NULL) { isc_mem_free(sock->worker->mctx, sock->h2->query_data); - sock->h2->query_data = NULL; } INSIST(sock->h2->connect.cstream == NULL); @@ -3673,7 +3668,6 @@ isc__nm_http_cleanup_data(isc_nmsocket_t *sock) { if (sock->h2->connect.uri != NULL) { isc_mem_free(sock->worker->mctx, sock->h2->connect.uri); - sock->h2->connect.uri = NULL; } isc__nm_httpsession_detach(&sock->h2->session); } diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index cccddf8d778..198083fdd46 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -498,7 +498,6 @@ nmsocket_cleanup(void *arg) { */ isc_mem_cput(sock->worker->mctx, sock->children, sock->nchildren, sizeof(*sock)); - sock->children = NULL; sock->nchildren = 0; } diff --git a/lib/ns/client.c b/lib/ns/client.c index 439a3168a4b..da97367883c 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -227,7 +227,6 @@ client_zoneversion_reset(ns_client_t *client) { } isc_mem_put(client->manager->mctx, client->zoneversion, client->zoneversionlength); - client->zoneversion = NULL; client->zoneversionlength = 0; } diff --git a/lib/ns/query.c b/lib/ns/query.c index b6f181a7fda..9ccda552f84 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -805,7 +805,6 @@ query_reset(ns_client_t *client, bool everything) { if (client->query.dns64_aaaaok != NULL) { isc_mem_cput(client->manager->mctx, client->query.dns64_aaaaok, client->query.dns64_aaaaoklen, sizeof(bool)); - client->query.dns64_aaaaok = NULL; client->query.dns64_aaaaoklen = 0; } @@ -847,7 +846,6 @@ query_reset(ns_client_t *client, bool everything) { if (everything) { isc_mem_put(client->manager->mctx, client->query.rpz_st, sizeof(*client->query.rpz_st)); - client->query.rpz_st = NULL; } } if (client->query.qc != NULL) { diff --git a/lib/ns/server.c b/lib/ns/server.c index 3d687ea9e71..44fb9cc0c74 100644 --- a/lib/ns/server.c +++ b/lib/ns/server.c @@ -213,7 +213,6 @@ ns_server_setserverid(ns_server_t *sctx, const char *serverid) { if (sctx->server_id != NULL) { isc_mem_free(sctx->mctx, sctx->server_id); - sctx->server_id = NULL; } if (serverid != NULL) { diff --git a/tests/isc/mem_test.c b/tests/isc/mem_test.c index 7111b521413..823e46ca940 100644 --- a/tests/isc/mem_test.c +++ b/tests/isc/mem_test.c @@ -76,7 +76,6 @@ ISC_RUN_TEST_IMPL(isc_mem_get) { */ for (i = 0; i < 11; i++) { isc_mempool_put(mp1, items1[i]); - items1[i] = NULL; } #if !__SANITIZE_ADDRESS__ @@ -102,7 +101,6 @@ ISC_RUN_TEST_IMPL(isc_mem_get) { } for (i = 0; i < 50; i++) { isc_mempool_put(mp2, items2[i]); - items2[i] = NULL; } } @@ -111,7 +109,6 @@ ISC_RUN_TEST_IMPL(isc_mem_get) { */ for (i = 11; i < MP1_MAXALLOC; i++) { isc_mempool_put(mp1, items1[i]); - items1[i] = NULL; } isc_mempool_destroy(&mp1);