This is an automated email from the ASF dual-hosted git repository.

bneradt 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 cab3015be6 Fix race of shutdown & retry of CacheDir unit test (#10659)
cab3015be6 is described below

commit cab3015be6e88a4ff1c5d4b31aa2e427ec4a0061
Author: Masaori Koshiba <[email protected]>
AuthorDate: Tue Oct 24 02:03:27 2023 +0900

    Fix race of shutdown & retry of CacheDir unit test (#10659)
    
    Fix #10657.
    
    The cache_init_success_callback can be called twice when the try-lock is 
failed and retry event is scheduled. It can be cause of double free.
    
    To fix this, we should delete CacheDirTest only if all test is done. Also, 
I thought we need TerminalTest continuation to shutdown the test, but it looks 
like we can just call test_done() function directly.
---
 src/iocore/cache/unit_tests/test_CacheDir.cc | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/src/iocore/cache/unit_tests/test_CacheDir.cc 
b/src/iocore/cache/unit_tests/test_CacheDir.cc
index c6e32e9ec9..aa3660ab15 100644
--- a/src/iocore/cache/unit_tests/test_CacheDir.cc
+++ b/src/iocore/cache/unit_tests/test_CacheDir.cc
@@ -21,6 +21,7 @@
   limitations under the License.
  */
 
+#include "Event.h"
 #include "main.h"
 
 #include "P_CacheDir.h"
@@ -73,21 +74,6 @@ class CacheDirTest : public CacheInit
 public:
   int
   cache_init_success_callback(int event, void *e) override
-  {
-    // Test
-    _run();
-
-    // Teardown
-    TerminalTest *tt = new TerminalTest;
-    this_ethread()->schedule_imm(tt);
-    delete this;
-
-    return 0;
-  }
-
-private:
-  void
-  _run()
   {
     ink_hrtime ttime;
 
@@ -99,7 +85,7 @@ private:
     MUTEX_TRY_LOCK(lock, vol->mutex, thread);
     if (!lock.is_locked()) {
       CONT_SCHED_LOCK_RETRY(this);
-      return;
+      return EVENT_DONE;
     }
 
     vol_dir_clear(vol);
@@ -250,6 +236,12 @@ private:
 #endif
     }
     vol_dir_clear(vol);
+
+    // Teardown
+    test_done();
+    delete this;
+
+    return EVENT_DONE;
   }
 };
 

Reply via email to