]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
simplify code around isc_mem_put() and isc_mem_free()
authorEvan Hunt <each@isc.org>
Wed, 28 May 2025 06:04:33 +0000 (23:04 -0700)
committerEvan Hunt <each@isc.org>
Thu, 29 May 2025 00:22:32 +0000 (17:22 -0700)
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.

22 files changed:
bin/dnssec/dnssec-revoke.c
bin/named/config.c
bin/named/server.c
bin/named/tsigconf.c
bin/nsupdate/nsupdate.c
bin/tools/mdig.c
lib/dns/adb.c
lib/dns/catz.c
lib/dns/keytable.c
lib/dns/message.c
lib/dns/remote.c
lib/dns/resconf.c
lib/dns/tsig.c
lib/dns/view.c
lib/dns/zone.c
lib/isc/log.c
lib/isc/netmgr/http.c
lib/isc/netmgr/netmgr.c
lib/ns/client.c
lib/ns/query.c
lib/ns/server.c
tests/isc/mem_test.c

index 8c647fefd625e71f876482f35840254e05f8cf54..9dbbb3cf84d7c0e08f95cea9bfa2ffccf211fd8e 100644 (file)
@@ -155,7 +155,6 @@ main(int argc, char **argv) {
                }
                if (strcmp(dir, ".") == 0) {
                        isc_mem_free(mctx, dir);
-                       dir = NULL;
                }
        }
 
index e23f95111f4ccbc8d3690237bac282604117276d..babf61ad8f1500aa66a923a4319520897e036f5c 100644 (file)
@@ -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);
index 756ea9a0c688b38352c3ecbde2b3b99d8e920343..9d7d0e0c550f8f84cafc8749bd20a026440d2d7b 100644 (file)
@@ -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) {
index 564e1ca0876e3a991ba23fdc746937e0fa7d20bc..fd6e94c0c2fb0bfb56296acde516b8254399f12b 100644 (file)
@@ -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);
                }
index 3c8e8578215501541d086db8f7d22ddffc06387e..ee2822711515cd24a5d738fba4121c25f74dc35f 100644 (file)
@@ -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);
index a9d0975efd8232f987cbaa034d2e3c0fcd07ef20..24ef6e9cdc7c621bbf976f2c8d6f46b898fc19c3 100644 (file)
@@ -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);
        }
index d95ae44bd1d49371cdbbb7ef421931ead764b757..ef37c987db8436ee5d8acffea55816198e714ac7 100644 (file)
@@ -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;
        }
 
index 6a83146f26f96da86e8ce114d6e64b391e9208cc..638c90dbe790739f67245966114dd758011445a7 100644 (file)
@@ -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) {
index 15c204f08a2c97d34f440e8a57bec266695745c1..2caae9612c780bf1afae8830c0497c217d5075e9 100644 (file)
@@ -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);
index b387dc11f2f893782af95bf71e857ee6372b3424..2c44154406404fd636c40779b782e4c12ea23e9c 100644 (file)
@@ -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
index e1e50d58e4e756d279b6a3c5c86d26e4efabf0b5..2ce059dccfdd701573b2e21af0d6b34ab0a935e4 100644 (file)
@@ -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;
index 00df0094a80593a9d49dfbadc8bad378ba766ff9..0b7c3eb151e4e4b4398a7b689bad4fdea94379c5 100644 (file)
@@ -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;
        }
 
        /*
index 376bde418f0c0177597311c4640cac82dc7ee166..211cba9dd8fbe0910cc335e3857b65d89fd53930 100644 (file)
@@ -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);
index 489fc70a1b6bbf623bc5cff69d0add12b5317f30..0cdf603db36d827290ec60e67503074d95929b4d 100644 (file)
@@ -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) {
index 1ee46b7565ce0dd1e0052029c73f734320c78758..cecad687253716231dd16b722187ca4371953f8f 100644 (file)
@@ -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) {
index b27049f56160a7d63d6dac07d34a63144651c61d..6ffd454750c409a007ad7e4e2dca1d21cdbd0882 100644 (file)
@@ -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;
        }
 }
 
index 7e138332eebe6a7dde2f385943bcb2c9e63541b9..3a6ba669212897476f00ee836a6b3b655889ddde 100644 (file)
@@ -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);
                        }
index cccddf8d778fad649602e06303af06a2118c4d09..198083fdd46f014b176f73cea39f0446307f2fdd 100644 (file)
@@ -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;
        }
 
index 439a3168a4ba65a10455220f6a9f3d03e164088c..da97367883c2926c16541d3654a46518ebffdfe3 100644 (file)
@@ -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;
 }
 
index b6f181a7fda8d708284b96d2a12597b19978a6bb..9ccda552f84a85df6d0401b30d8563b5568f86a4 100644 (file)
@@ -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) {
index 3d687ea9e71fdfe270c2cbf7b8aa199351001337..44fb9cc0c74ac56bac7b82879d8a2926d6c37d02 100644 (file)
@@ -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) {
index 7111b521413a9a57fcd835c7bb719bc48a69cf64..823e46ca94028251f1fc7db95f62472c64b3dc6f 100644 (file)
@@ -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);