This is an automated email from the ASF dual-hosted git repository.
bcall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 5cc0657 Fixed clang-analyzer issue with memory leak in LogHostList
5cc0657 is described below
commit 5cc0657e7db6539acb7ca92c627c8db4c38a4aec
Author: Bryan Call <[email protected]>
AuthorDate: Tue May 22 14:27:23 2018 -0700
Fixed clang-analyzer issue with memory leak in LogHostList
---
proxy/logging/LogBuffer.h | 3 ++-
proxy/logging/LogHost.cc | 27 ++++++++-------------------
proxy/logging/LogHost.h | 4 ++--
3 files changed, 12 insertions(+), 22 deletions(-)
diff --git a/proxy/logging/LogBuffer.h b/proxy/logging/LogBuffer.h
index b129a6c..1a7138e 100644
--- a/proxy/logging/LogBuffer.h
+++ b/proxy/logging/LogBuffer.h
@@ -193,7 +193,7 @@ public:
char *alt_printf_str = nullptr);
static void
- destroy(LogBuffer *lb)
+ destroy(LogBuffer *&lb)
{
// ink_atomic_increment() returns the previous value, so when it was 1, we
are
// the thread that decremented to zero and should delete ...
@@ -201,6 +201,7 @@ public:
if (refcnt == 1) {
delete lb;
+ lb = nullptr;
}
ink_release_assert(refcnt >= 0);
diff --git a/proxy/logging/LogHost.cc b/proxy/logging/LogHost.cc
index fbbc034..981bd12 100644
--- a/proxy/logging/LogHost.cc
+++ b/proxy/logging/LogHost.cc
@@ -248,7 +248,7 @@ LogHost::disconnect()
// and try to delete it when its reference become zero.
//
bool
-LogHost::preproc_and_try_delete(LogBuffer *lb)
+LogHost::preproc_and_try_delete(LogBuffer *&lb)
{
if (lb == nullptr) {
Note("Cannot write LogBuffer to LogHost %s; LogBuffer is NULL", name());
@@ -272,7 +272,7 @@ LogHost::preproc_and_try_delete(LogBuffer *lb)
ink_assert(m_log_collation_client_sm != nullptr);
}
- // send log_buffer;
+ // send log_buffer
if (m_log_collation_client_sm->send(lb) <= 0) {
goto done;
}
@@ -289,7 +289,7 @@ done:
// try to delete it when its reference become zero.
//
void
-LogHost::orphan_write_and_try_delete(LogBuffer *lb)
+LogHost::orphan_write_and_try_delete(LogBuffer *&lb)
{
RecIncrRawStat(log_rsb, this_thread()->mutex->thread_holding,
log_stat_num_lost_before_sent_to_network_stat,
lb->header()->entry_count);
@@ -418,33 +418,22 @@ LogHostList::preproc_and_try_delete(LogBuffer *lb)
available_host = lh;
do {
-#ifndef __clang_analyzer__
ink_atomic_increment(&lb->m_references, 1);
- success = lh->preproc_and_try_delete(lb);
-#else
- /* clang-analyzer cannot be sure that lb->m_references
- * isn't being modified problematically simultaneously
- * in other threads. It, however, mustn't be or all is
- * already lost. Suppress clang-analyzer for this case
- * so that it does not erroneously believe a use after
- * free occurs here.
- */
- success = false;
-#endif
+ success = lh->preproc_and_try_delete(lb);
need_orphan = need_orphan && (success == false);
} while (lb && (success == false) && (lh = lh->failover_link.next));
nr--;
}
-#ifndef __clang_analyzer__
- if (need_orphan && available_host) {
+ if (lb != nullptr && need_orphan && available_host) {
ink_atomic_increment(&lb->m_references, 1);
available_host->orphan_write_and_try_delete(lb);
}
-#endif
- LogBuffer::destroy(lb);
+ if (lb != nullptr) {
+ LogBuffer::destroy(lb);
+ }
return 0;
}
diff --git a/proxy/logging/LogHost.h b/proxy/logging/LogHost.h
index e3e7e05..cb62e10 100644
--- a/proxy/logging/LogHost.h
+++ b/proxy/logging/LogHost.h
@@ -52,13 +52,13 @@ public:
// preprocess the given buffer data before sent to target host
// and try to delete it when its reference become zero.
//
- bool preproc_and_try_delete(LogBuffer *lb);
+ bool preproc_and_try_delete(LogBuffer *&lb);
//
// write the given buffer data to orphan file and
// try to delete it when its reference become zero.
//
- void orphan_write_and_try_delete(LogBuffer *lb);
+ void orphan_write_and_try_delete(LogBuffer *&lb);
const char *
name() const
--
To stop receiving notification emails like this one, please contact
[email protected].