2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 10:10:06 +00:00

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.
This commit is contained in:
Evan Hunt 2025-05-27 23:04:33 -07:00
parent 87ad162463
commit dd9a685f4a
22 changed files with 0 additions and 53 deletions

View File

@ -155,7 +155,6 @@ main(int argc, char **argv) {
}
if (strcmp(dir, ".") == 0) {
isc_mem_free(mctx, dir);
dir = NULL;
}
}

View 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);

View 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) {

View 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);
}

View 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);

View 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);
}

View 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;
}

View 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) {

View 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);

View 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

View 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;

View 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;
}
/*

View 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);

View 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) {

View 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) {

View 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;
}
}

View 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);
}

View 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;
}

View 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;
}

View 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) {

View 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) {

View 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);