JosiahWI commented on code in PR #11634:
URL: https://github.com/apache/trafficserver/pull/11634#discussion_r1700861654


##########
src/iocore/cache/unit_tests/stub.cc:
##########
@@ -27,6 +27,29 @@
 
 #include "proxy/HttpAPIHooks.h"
 
+#include "tscore/BaseLogFile.h"
+#include "tscore/Diags.h"
+
+class InitDiags
+{
+public:
+  InitDiags() : base_log_file{new BaseLogFile("stderr")}
+  {
+    DiagsPtr::set(new Diags("cache unit test", "*" /* tags */, "" /* actions 
*/, this->base_log_file));
+  }
+
+  ~InitDiags() { delete this->base_log_file; }
+
+private:
+  BaseLogFile *base_log_file;
+};
+
+// The FetchSM class allocator below uses the diags in its constructor, so we
+// force them to be initialized prior to that. This gets "leaked" at shutdown
+// to ensure that the log file remains valid if accessed by other threads
+// during static object destruction.
+InitDiags const *g_init_diags_dummy = new InitDiags{};

Review Comment:
   That calls could result in a use after three of the log handle, which I 
think is worse. I'm considering suppressing the ASan report, but I don't like 
that either. There's really no way to make this work with the current design.



##########
src/iocore/cache/unit_tests/stub.cc:
##########
@@ -27,6 +27,29 @@
 
 #include "proxy/HttpAPIHooks.h"
 
+#include "tscore/BaseLogFile.h"
+#include "tscore/Diags.h"
+
+class InitDiags
+{
+public:
+  InitDiags() : base_log_file{new BaseLogFile("stderr")}
+  {
+    DiagsPtr::set(new Diags("cache unit test", "*" /* tags */, "" /* actions 
*/, this->base_log_file));
+  }
+
+  ~InitDiags() { delete this->base_log_file; }
+
+private:
+  BaseLogFile *base_log_file;
+};
+
+// The FetchSM class allocator below uses the diags in its constructor, so we
+// force them to be initialized prior to that. This gets "leaked" at shutdown
+// to ensure that the log file remains valid if accessed by other threads
+// during static object destruction.
+InitDiags const *g_init_diags_dummy = new InitDiags{};

Review Comment:
   That could result in a use after three of the log handle, which I think is 
worse. I'm considering suppressing the ASan report, but I don't like that 
either. There's really no way to make this work with the current design.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to