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

wangdan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new 3290bcae9 test: fix heap-use-after-free issue in 
`test_disable_backup_policy` caused by unfinished task (#2315)
3290bcae9 is described below

commit 3290bcae9594c0f4e0bbc9edf49265c2606cf03b
Author: Dan Wang <[email protected]>
AuthorDate: Wed Nov 5 20:45:40 2025 +0800

    test: fix heap-use-after-free issue in `test_disable_backup_policy` caused 
by unfinished task (#2315)
    
    Fix https://github.com/apache/incubator-pegasus/issues/2281.
    
    In `test_disable_backup_policy`, `continue_current_backup_unlocked()`
    is invoked, which in turn calls `issue_new_backup_unlocked()` onto `_mp`
    as the callback function where if `_policy.is_disable` is set to `true`, the
    callback will recursively reschedule itself through the thread pool. After 
the
    test has finished and `_mp` has been destructed, however, the background
    thread may be still executing the callback, where accessing members inside
    `_mp` will lead to a heap-use-after-free error. The solution is to stop all
    running tasks on `_mp` before the unit test exits.
---
 src/meta/test/backup_test.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/meta/test/backup_test.cpp b/src/meta/test/backup_test.cpp
index 13e119617..640febcc6 100644
--- a/src/meta/test/backup_test.cpp
+++ b/src/meta/test/backup_test.cpp
@@ -51,6 +51,7 @@
 #include "task/async_calls.h"
 #include "task/task.h"
 #include "task/task_code.h"
+#include "task/task_tracker.h"
 #include "utils/autoref_ptr.h"
 #include "utils/chrono_literals.h"
 #include "utils/error_code.h"
@@ -599,6 +600,8 @@ TEST_F(policy_context_test, test_disable_backup_policy)
     // 'start_backup_app_meta_unlocked()' should not be called because policy 
is disabled
     _mp.continue_current_backup_unlocked();
     ASSERT_FALSE(_mp.notifier_start_backup_app_meta_unlocked().wait_for(5000));
+
+    _mp._tracker.cancel_outstanding_tasks();
 }
 
 TEST_F(policy_context_test, test_backup_failed)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to