From: Joshua Rogers Date: Mon, 8 Sep 2025 09:37:01 +0000 (+0000) Subject: Avoid memory leaks when logging to MS Windows syslog (#2154) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5c25cfef8c667aeda5631d8677a623d7a70f1891;p=thirdparty%2Fsquid.git Avoid memory leaks when logging to MS Windows syslog (#2154) --- diff --git a/compat/mswindows.cc b/compat/mswindows.cc index 5d24b04a96..6ce80cd379 100644 --- a/compat/mswindows.cc +++ b/compat/mswindows.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #if HAVE_PSAPI_H #include @@ -204,7 +205,6 @@ void syslog(int priority, const char *fmt, ...) { WORD logtype; - char *str=static_cast(xmalloc(SYSLOG_MAX_MSG_SIZE)); int str_len; va_list ap; @@ -212,7 +212,8 @@ syslog(int priority, const char *fmt, ...) return; va_start(ap, fmt); - str_len = vsnprintf(str, SYSLOG_MAX_MSG_SIZE-1, fmt, ap); + auto buf = std::make_unique(SYSLOG_MAX_MSG_SIZE); + str_len = vsnprintf(buf.get(), SYSLOG_MAX_MSG_SIZE, fmt, ap); va_end(ap); if (str_len < 0) { @@ -241,8 +242,9 @@ syslog(int priority, const char *fmt, ...) } //Windows API suck. They are overengineered + const auto strings[1] = { buf.get() }; ReportEventA(ms_eventlog, logtype, 0, 0, nullptr, 1, 0, - const_cast(&str), nullptr); + strings, nullptr); } /* note: this is all MSWindows-specific code; all of it should be conditional */