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 84f3efe8cf Coverity 1497333: Resource leak in object in LogConfig
(#10891)
84f3efe8cf is described below
commit 84f3efe8cf8f33434f4769e976b5bda09273a706
Author: Bryan Call <[email protected]>
AuthorDate: Fri Dec 1 08:31:29 2023 -0800
Coverity 1497333: Resource leak in object in LogConfig (#10891)
hostname wasn't freed and minor cleanup
---
include/proxy/logging/LogConfig.h | 46 ++++++++++++++++++---------------------
include/proxy/logging/LogLimits.h | 4 ++--
src/proxy/logging/LogConfig.cc | 40 ++++------------------------------
3 files changed, 27 insertions(+), 63 deletions(-)
diff --git a/include/proxy/logging/LogConfig.h
b/include/proxy/logging/LogConfig.h
index 8a02bb1e49..3561fa5ade 100644
--- a/include/proxy/logging/LogConfig.h
+++ b/include/proxy/logging/LogConfig.h
@@ -158,7 +158,6 @@ public:
*/
void register_rolled_log_auto_delete(std::string_view logname, int
rolling_min_count);
-public:
bool initialized = false;
bool reconfiguration_needed = false;
bool logging_space_exhausted = false;
@@ -171,31 +170,31 @@ public:
LogFilterList filter_list;
LogFormatList format_list;
- int log_buffer_size;
- bool log_fast_buffer;
- int max_secs_per_buffer;
- int max_space_mb_for_logs;
- int max_space_mb_headroom;
- int logfile_perm;
+ uint32_t log_buffer_size = 10 * LOG_KILOBYTE;
+ bool log_fast_buffer = false;
+ int max_secs_per_buffer = 5;
+ int max_space_mb_for_logs = 100;
+ int max_space_mb_headroom = 10;
+ int logfile_perm = 0644;
- int preproc_threads;
+ int preproc_threads = 1;
- Log::RollingEnabledValues rolling_enabled;
- int rolling_interval_sec;
- int rolling_offset_hr;
- int rolling_size_mb;
- int rolling_min_count;
- int rolling_max_count;
- bool rolling_allow_empty;
- bool auto_delete_rolled_files;
+ Log::RollingEnabledValues rolling_enabled = Log::NO_ROLLING;
+ int rolling_interval_sec = 86400;
+ int rolling_offset_hr = 0;
+ int rolling_size_mb = 10;
+ int rolling_min_count = 0;
+ int rolling_max_count = 0;
+ bool rolling_allow_empty = false;
+ bool auto_delete_rolled_files = false;
- int sampling_frequency;
- int file_stat_frequency;
- int space_used_frequency;
+ int sampling_frequency = 1;
+ int file_stat_frequency = 16;
+ int space_used_frequency = 900;
- int ascii_buffer_size;
- int max_line_size;
- int logbuffer_max_iobuf_index;
+ int ascii_buffer_size = 4 * 9216;
+ int max_line_size = 9216;
+ int logbuffer_max_iobuf_index = BUFFER_SIZE_INDEX_32K;
char *hostname = nullptr;
char *logfile_dir = nullptr;
@@ -204,9 +203,6 @@ public:
private:
bool evaluate_config();
- void setup_default_values();
-
-private:
bool m_disk_full = false;
bool m_disk_low = false;
bool m_partition_full = false;
diff --git a/include/proxy/logging/LogLimits.h
b/include/proxy/logging/LogLimits.h
index d5e7505b94..568f19386c 100644
--- a/include/proxy/logging/LogLimits.h
+++ b/include/proxy/logging/LogLimits.h
@@ -34,5 +34,5 @@ enum {
LOG_MAX_FORMATTED_LINE = 10240
};
-#define LOG_KILOBYTE ((int64_t)1024)
-#define LOG_MEGABYTE ((int64_t)1048576)
+constexpr int64_t LOG_KILOBYTE = 1024;
+constexpr int64_t LOG_MEGABYTE = 1048576;
diff --git a/src/proxy/logging/LogConfig.cc b/src/proxy/logging/LogConfig.cc
index 4ef25ef8cf..bd80f6b91c 100644
--- a/src/proxy/logging/LogConfig.cc
+++ b/src/proxy/logging/LogConfig.cc
@@ -66,40 +66,6 @@
#define DIAGS_LOG_FILENAME "diags.log"
#define MANAGER_LOG_FILENAME "manager.log"
-void
-LogConfig::setup_default_values()
-{
- hostname = ats_strdup(Machine::instance()->host_name.c_str());
- log_buffer_size = static_cast<int>(10 * LOG_KILOBYTE);
- log_fast_buffer = false;
- max_secs_per_buffer = 5;
- max_space_mb_for_logs = 100;
- max_space_mb_headroom = 10;
- error_log_filename = ats_strdup("error.log");
- logfile_perm = 0644;
- logfile_dir = ats_strdup(".");
-
- preproc_threads = 1;
-
- rolling_enabled = Log::NO_ROLLING;
- rolling_interval_sec = 86400; // 24 hours
- rolling_offset_hr = 0;
- rolling_size_mb = 10;
- rolling_min_count = 0;
- rolling_max_count = 0;
- rolling_allow_empty = false;
- auto_delete_rolled_files = true;
- roll_log_files_now = false;
-
- sampling_frequency = 1;
- file_stat_frequency = 16;
- space_used_frequency = 900;
-
- ascii_buffer_size = 4 * 9216;
- max_line_size = 9216; // size of pipe buffer for SunOS 5.6
- logbuffer_max_iobuf_index = BUFFER_SIZE_INDEX_32K;
-}
-
void
LogConfig::reconfigure_mgmt_variables(swoc::MemSpan<void>)
{
@@ -294,8 +260,9 @@ LogConfig::LogConfig() :
m_partition_space_left(static_cast<int64_t>(UINT_MAX))
// Setup the default values for all LogConfig public variables so that
// a LogConfig object is valid upon return from the constructor even
// if no configuration file is read
- //
- setup_default_values();
+ hostname = ats_strdup(Machine::instance()->host_name.c_str());
+ error_log_filename = ats_strdup("error.log");
+ logfile_dir = ats_strdup(".");
}
/*-------------------------------------------------------------------------
@@ -306,6 +273,7 @@ LogConfig::LogConfig() :
m_partition_space_left(static_cast<int64_t>(UINT_MAX))
LogConfig::~LogConfig()
{
+ ats_free(hostname);
ats_free(error_log_filename);
ats_free(logfile_dir);
}