You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by rr...@apache.org on 2022/03/29 17:01:47 UTC
[trafficserver] branch 9.2.x updated: Remove null check before ats_free calls (#8744) (#8770)
This is an automated email from the ASF dual-hosted git repository.
rrm pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/9.2.x by this push:
new e29e244 Remove null check before ats_free calls (#8744) (#8770)
e29e244 is described below
commit e29e244ea20dcdbe150b7d98d5a3f9dd09fc0d70
Author: Randall Meyer <rr...@apache.org>
AuthorDate: Tue Mar 29 10:01:36 2022 -0700
Remove null check before ats_free calls (#8744) (#8770)
ats_free already does null checks
(cherry picked from commit 1845b7eb3b2faa66b9422df7c95f0ab514cdb895)
Conflicts:
iocore/net/TLSTunnelSupport.cc
---
iocore/cache/CacheHosting.cc | 12 +++---------
iocore/cache/P_CacheInternal.h | 6 +++---
iocore/net/ALPNSupport.cc | 9 ++++-----
iocore/net/OCSPStapling.cc | 19 ++++++-------------
iocore/net/SSLNextProtocolSet.cc | 6 ++----
iocore/net/UnixUDPNet.cc | 2 +-
lib/records/RecCore.cc | 6 +++---
lib/records/RecUtils.cc | 4 +---
lib/records/test_RecProcess.i | 2 +-
plugins/experimental/memcache/tsmemcache.cc | 12 ++++++------
proxy/http/HttpSM.cc | 8 +++-----
proxy/http/remap/RemapConfig.cc | 9 ++++-----
proxy/http/remap/UrlMapping.h | 6 ++----
proxy/http/remap/UrlRewrite.cc | 4 +---
proxy/http/remap/unit-tests/nexthop_test_stubs.cc | 6 +++---
proxy/http2/Http2Stream.cc | 5 ++---
proxy/http3/QPACK.cc | 6 ++----
proxy/logging/LogFormat.cc | 18 ++++++++----------
src/traffic_server/InkAPI.cc | 18 +++++++-----------
19 files changed, 62 insertions(+), 96 deletions(-)
diff --git a/iocore/cache/CacheHosting.cc b/iocore/cache/CacheHosting.cc
index 41c9957..e98793f 100644
--- a/iocore/cache/CacheHosting.cc
+++ b/iocore/cache/CacheHosting.cc
@@ -490,18 +490,14 @@ CacheHostRecord::Init(matcher_line *line_info, CacheType typ)
const char *errptr = "A volume number expected";
RecSignalWarning(REC_SIGNAL_CONFIG_ERROR, "%s discarding %s entry at line %d :%s", "[CacheHosting]", config_file,
line_info->line_num, errptr);
- if (val != nullptr) {
- ats_free(val);
- }
+ ats_free(val);
return -1;
}
}
if ((*s < '0') || (*s > '9')) {
RecSignalWarning(REC_SIGNAL_CONFIG_ERROR, "%s discarding %s entry at line %d : bad token [%c]", "[CacheHosting]",
config_file, line_info->line_num, *s);
- if (val != nullptr) {
- ats_free(val);
- }
+ ats_free(val);
return -1;
}
s++;
@@ -537,9 +533,7 @@ CacheHostRecord::Init(matcher_line *line_info, CacheType typ)
if (!is_vol_present) {
RecSignalWarning(REC_SIGNAL_CONFIG_ERROR, "%s discarding %s entry at line %d : bad volume number [%d]",
"[CacheHosting]", config_file, line_info->line_num, volume_number);
- if (val != nullptr) {
- ats_free(val);
- }
+ ats_free(val);
return -1;
}
if (c == '\0') {
diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h
index 756eb14..8630d3a 100644
--- a/iocore/cache/P_CacheInternal.h
+++ b/iocore/cache/P_CacheInternal.h
@@ -614,9 +614,9 @@ free_CacheVC(CacheVC *cont)
cont->blocks.clear();
cont->writer_buf.clear();
cont->alternate_index = CACHE_ALT_INDEX_DEFAULT;
- if (cont->scan_vol_map) {
- ats_free(cont->scan_vol_map);
- }
+
+ ats_free(cont->scan_vol_map);
+
memset((char *)&cont->vio, 0, cont->size_to_init);
#ifdef CACHE_STAT_PAGES
ink_assert(!cont->stat_link.next && !cont->stat_link.prev);
diff --git a/iocore/net/ALPNSupport.cc b/iocore/net/ALPNSupport.cc
index 69b8b1c..1e9bc8a 100644
--- a/iocore/net/ALPNSupport.cc
+++ b/iocore/net/ALPNSupport.cc
@@ -57,11 +57,10 @@ ALPNSupport::unbind(SSL *ssl)
void
ALPNSupport::clear()
{
- if (npn) {
- ats_free(npn);
- npn = nullptr;
- npnsz = 0;
- }
+ ats_free(npn);
+ npn = nullptr;
+ npnsz = 0;
+
npnSet = nullptr;
npnEndpoint = nullptr;
}
diff --git a/iocore/net/OCSPStapling.cc b/iocore/net/OCSPStapling.cc
index d572165..da5a8c1 100644
--- a/iocore/net/OCSPStapling.cc
+++ b/iocore/net/OCSPStapling.cc
@@ -77,12 +77,10 @@ certinfo_map_free(void * /*parent*/, void *ptr, CRYPTO_EX_DATA * /*ad*/, int /*i
if (cinf->uri) {
OPENSSL_free(cinf->uri);
}
- if (cinf->certname) {
- ats_free(cinf->certname);
- }
- if (cinf->user_agent) {
- ats_free(cinf->user_agent);
- }
+
+ ats_free(cinf->certname);
+ ats_free(cinf->user_agent);
+
ink_mutex_destroy(&cinf->stapling_mutex);
OPENSSL_free(cinf);
}
@@ -295,13 +293,8 @@ err:
OCSP_CERTID_free(cinf->cid);
}
- if (cinf->certname) {
- ats_free(cinf->certname);
- }
-
- if (cinf->user_agent) {
- ats_free(cinf->user_agent);
- }
+ ats_free(cinf->certname);
+ ats_free(cinf->user_agent);
if (cinf) {
OPENSSL_free(cinf);
diff --git a/iocore/net/SSLNextProtocolSet.cc b/iocore/net/SSLNextProtocolSet.cc
index 99df1f8..903144e 100644
--- a/iocore/net/SSLNextProtocolSet.cc
+++ b/iocore/net/SSLNextProtocolSet.cc
@@ -49,10 +49,8 @@ SSLNextProtocolSet::create_npn_advertisement(const SessionProtocolSet &enabled,
const SSLNextProtocolSet::NextProtocolEndpoint *ep;
unsigned char *advertised;
- if (*npn) {
- ats_free(*npn);
- *npn = nullptr;
- }
+ ats_free(*npn);
+ *npn = nullptr;
*len = 0;
for (ep = endpoints.head; ep != nullptr; ep = endpoints.next(ep)) {
diff --git a/iocore/net/UnixUDPNet.cc b/iocore/net/UnixUDPNet.cc
index 2442348..6f64a59 100644
--- a/iocore/net/UnixUDPNet.cc
+++ b/iocore/net/UnixUDPNet.cc
@@ -505,7 +505,7 @@ UDPReadContinuation::readPollEvent(int event_, Event *e)
* *actual_len = recvfrom(fd,addr,buf->end(),len)
* if successful then
* buf->fill(*actual_len);
- * return ACTION_RESULT_DONE
+ * return ACTION_RESULT_DONE
* else if nothing read
* *actual_len is 0
* create "UDP read continuation" C with 'cont's lock
diff --git a/lib/records/RecCore.cc b/lib/records/RecCore.cc
index fcb6474..4fa791d 100644
--- a/lib/records/RecCore.cc
+++ b/lib/records/RecCore.cc
@@ -898,9 +898,9 @@ RecRegisterConfig(RecT rec_type, const char *name, RecDataT data_type, RecData d
// Note: do not modify 'record->config_meta.update_required'
r->config_meta.update_type = update_type;
r->config_meta.check_type = check_type;
- if (r->config_meta.check_expr) {
- ats_free(r->config_meta.check_expr);
- }
+
+ ats_free(r->config_meta.check_expr);
+
r->config_meta.check_expr = ats_strdup(check_expr);
r->config_meta.update_cb_list = nullptr;
r->config_meta.access_type = access_type;
diff --git a/lib/records/RecUtils.cc b/lib/records/RecUtils.cc
index e0cdbb8..9428041 100644
--- a/lib/records/RecUtils.cc
+++ b/lib/records/RecUtils.cc
@@ -129,9 +129,7 @@ RecDataSet(RecDataT data_type, RecData *data_dst, RecData *data_src)
}
} else if (((data_dst->rec_string) && (strcmp(data_dst->rec_string, data_src->rec_string) != 0)) ||
((data_dst->rec_string == nullptr) && (data_src->rec_string != nullptr))) {
- if (data_dst->rec_string) {
- ats_free(data_dst->rec_string);
- }
+ ats_free(data_dst->rec_string);
data_dst->rec_string = ats_strdup(data_src->rec_string);
rec_set = true;
diff --git a/lib/records/test_RecProcess.i b/lib/records/test_RecProcess.i
index 963c45d..e9c3c91 100644
--- a/lib/records/test_RecProcess.i
+++ b/lib/records/test_RecProcess.i
@@ -46,7 +46,7 @@ void RecDumpRecordsHt(RecT rec_type);
do { \
RecString rec_string = 0; \
if (RecGetRecordString_Xmalloc("proxy.config.parse_"name, &rec_string) != REC_ERR_FAIL) { \
- if (rec_string) ats_free(rec_string); \
+ ats_free(rec_string); \
printf(" parse_"name": FAIL\n"); \
failures++; \
} else { \
diff --git a/plugins/experimental/memcache/tsmemcache.cc b/plugins/experimental/memcache/tsmemcache.cc
index e8197ec..e207718 100644
--- a/plugins/experimental/memcache/tsmemcache.cc
+++ b/plugins/experimental/memcache/tsmemcache.cc
@@ -179,9 +179,9 @@ MC::die()
if (cbuf) {
free_MIOBuffer(cbuf);
}
- if (tbuf) {
- ats_free(tbuf);
- }
+
+ ats_free(tbuf);
+
mutex = NULL;
theMCAllocator.free(this);
return EVENT_DONE;
@@ -351,9 +351,9 @@ MC::read_from_client()
cbuf->clear();
}
ink_assert(!crvc && !cwvc);
- if (tbuf) {
- ats_free(tbuf);
- }
+
+ ats_free(tbuf);
+
return TS_SET_CALL(&MC::read_from_client_event, VC_EVENT_READ_READY, rvio);
}
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index 40fee62..6ee3681 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -7316,11 +7316,9 @@ HttpSM::kill_this()
HTTP_SM_SET_DEFAULT_HANDLER(nullptr);
- if (redirect_url != nullptr) {
- ats_free((void *)redirect_url);
- redirect_url = nullptr;
- redirect_url_len = 0;
- }
+ ats_free(redirect_url);
+ redirect_url = nullptr;
+ redirect_url_len = 0;
#ifdef USE_HTTP_DEBUG_LISTS
ink_mutex_acquire(&debug_sm_list_mutex);
diff --git a/proxy/http/remap/RemapConfig.cc b/proxy/http/remap/RemapConfig.cc
index 2089fb4..61afbd7 100644
--- a/proxy/http/remap/RemapConfig.cc
+++ b/proxy/http/remap/RemapConfig.cc
@@ -899,11 +899,10 @@ process_regex_mapping_config(const char *from_host_lower, url_mapping *new_mappi
return true;
lFail:
- if (reg_map->to_url_host_template) {
- ats_free(reg_map->to_url_host_template);
- reg_map->to_url_host_template = nullptr;
- reg_map->to_url_host_template_len = 0;
- }
+ ats_free(reg_map->to_url_host_template);
+ reg_map->to_url_host_template = nullptr;
+ reg_map->to_url_host_template_len = 0;
+
return false;
}
diff --git a/proxy/http/remap/UrlMapping.h b/proxy/http/remap/UrlMapping.h
index c826c4a..bb25e36 100644
--- a/proxy/http/remap/UrlMapping.h
+++ b/proxy/http/remap/UrlMapping.h
@@ -64,10 +64,8 @@ public:
~redirect_tag_str()
{
type = 0;
- if (chunk_str) {
- ats_free(chunk_str);
- chunk_str = nullptr;
- }
+ ats_free(chunk_str);
+ chunk_str = nullptr;
}
redirect_tag_str *next = nullptr;
diff --git a/proxy/http/remap/UrlRewrite.cc b/proxy/http/remap/UrlRewrite.cc
index 85dd19f..96de22b 100644
--- a/proxy/http/remap/UrlRewrite.cc
+++ b/proxy/http/remap/UrlRewrite.cc
@@ -957,9 +957,7 @@ UrlRewrite::_destroyList(RegexMappingList &mappings)
RegexMapping *list_iter;
while ((list_iter = mappings.pop()) != nullptr) {
delete list_iter->url_map;
- if (list_iter->to_url_host_template) {
- ats_free(list_iter->to_url_host_template);
- }
+ ats_free(list_iter->to_url_host_template);
delete list_iter;
}
mappings.clear();
diff --git a/proxy/http/remap/unit-tests/nexthop_test_stubs.cc b/proxy/http/remap/unit-tests/nexthop_test_stubs.cc
index 5213eb9..b72183b 100644
--- a/proxy/http/remap/unit-tests/nexthop_test_stubs.cc
+++ b/proxy/http/remap/unit-tests/nexthop_test_stubs.cc
@@ -102,9 +102,9 @@ build_request(int64_t sm_id, HttpSM *sm, sockaddr_in *ip, const char *os_hostnam
}
sm->t_state.request_data.hdr = new HTTPHdr();
sm->t_state.request_data.hdr->create(HTTP_TYPE_REQUEST, myHeap);
- if (sm->t_state.request_data.hostname_str != nullptr) {
- ats_free(sm->t_state.request_data.hostname_str);
- }
+
+ ats_free(sm->t_state.request_data.hostname_str);
+
sm->t_state.request_data.hostname_str = ats_strdup(os_hostname);
sm->t_state.request_data.xact_start = time(nullptr);
ink_zero(sm->t_state.request_data.src_ip);
diff --git a/proxy/http2/Http2Stream.cc b/proxy/http2/Http2Stream.cc
index a453c23..a2bb06f 100644
--- a/proxy/http2/Http2Stream.cc
+++ b/proxy/http2/Http2Stream.cc
@@ -130,9 +130,8 @@ Http2Stream::~Http2Stream()
read_vio.mutex.clear();
write_vio.mutex.clear();
- if (header_blocks) {
- ats_free(header_blocks);
- }
+ ats_free(header_blocks);
+
_clear_timers();
clear_io_events();
http_parser_clear(&http_parser);
diff --git a/proxy/http3/QPACK.cc b/proxy/http3/QPACK.cc
index ca937f7..6aec8f8 100644
--- a/proxy/http3/QPACK.cc
+++ b/proxy/http3/QPACK.cc
@@ -1823,10 +1823,8 @@ QPACK::DynamicTableStorage::DynamicTableStorage(uint16_t size) : _head(size * 2
QPACK::DynamicTableStorage::~DynamicTableStorage()
{
- if (this->_data) {
- ats_free(this->_data);
- this->_data = nullptr;
- }
+ ats_free(this->_data);
+ this->_data = nullptr;
}
void
diff --git a/proxy/logging/LogFormat.cc b/proxy/logging/LogFormat.cc
index 330bc19..c1f1901 100644
--- a/proxy/logging/LogFormat.cc
+++ b/proxy/logging/LogFormat.cc
@@ -142,21 +142,19 @@ LogFormat::init_variables(const char *name, const char *fieldlist_str, const cha
m_agg_marshal_space = static_cast<char *>(ats_malloc(m_field_count * INK_MIN_ALIGN));
}
- if (m_name_str) {
- ats_free(m_name_str);
- m_name_str = nullptr;
- m_name_id = 0;
- }
+ ats_free(m_name_str);
+ m_name_str = nullptr;
+ m_name_id = 0;
+
if (name) {
m_name_str = ats_strdup(name);
m_name_id = id_from_name(m_name_str);
}
- if (m_fieldlist_str) {
- ats_free(m_fieldlist_str);
- m_fieldlist_str = nullptr;
- m_fieldlist_id = 0;
- }
+ ats_free(m_fieldlist_str);
+ m_fieldlist_str = nullptr;
+ m_fieldlist_id = 0;
+
if (fieldlist_str) {
m_fieldlist_str = ats_strdup(fieldlist_str);
m_fieldlist_id = id_from_name(m_fieldlist_str);
diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc
index 861fcde..1f46cdf 100644
--- a/src/traffic_server/InkAPI.cc
+++ b/src/traffic_server/InkAPI.cc
@@ -850,12 +850,10 @@ FileImpl::fclose()
m_mode = CLOSED;
}
- if (m_buf) {
- ats_free(m_buf);
- m_buf = nullptr;
- m_bufsize = 0;
- m_bufpos = 0;
- }
+ ats_free(m_buf);
+ m_buf = nullptr;
+ m_bufsize = 0;
+ m_bufpos = 0;
}
ssize_t
@@ -8209,11 +8207,9 @@ TSHttpTxnRedirectUrlSet(TSHttpTxn txnp, const char *url, const int url_len)
HttpSM *sm = (HttpSM *)txnp;
- if (sm->redirect_url != nullptr) {
- ats_free(sm->redirect_url);
- sm->redirect_url = nullptr;
- sm->redirect_url_len = 0;
- }
+ ats_free(sm->redirect_url);
+ sm->redirect_url = nullptr;
+ sm->redirect_url_len = 0;
sm->redirect_url = (char *)url;
sm->redirect_url_len = url_len;