Skip to content

Commit c2a1a20

Browse files
committed
Fix ASAN stack-use-after-scope errors Basic/TaskQueueTest.cpp
The issue was that in three tests, the `Args` arrays were being declared inside for loops. When `TQ.addTask()` was called, it stored a pointer to the `Args` array. As the `Args` array was declared in the loop, it would go out of scope at the end of each iteration whilst `TaskQueue` held a pointer to it.
1 parent 0e4dc2f commit c2a1a20

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

unittests/Basic/TaskQueueTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ TEST(TaskQueueTest, HighConcurrency) {
149149
return TaskFinishedResponse::ContinueExecution;
150150
};
151151

152+
const char *Args[] = {"test", nullptr};
152153
for (int i = 0; i < 50; i++) {
153-
const char *Args[] = {"test", nullptr};
154154
TQ.addTask("/bin/echo", Args, llvm::ArrayRef<const char *>(), nullptr, false);
155155
}
156156

@@ -182,8 +182,8 @@ TEST(TaskQueueTest, TaskBeganCallback) {
182182
return TaskFinishedResponse::ContinueExecution;
183183
};
184184

185+
const char *Args[] = {"echo", "test", nullptr};
185186
for (int i = 0; i < 3; i++) {
186-
const char *Args[] = {"echo", "test", nullptr};
187187
TQ.addTask("/bin/echo", Args, llvm::ArrayRef<const char *>(), nullptr, false);
188188
}
189189

@@ -219,8 +219,8 @@ TEST(TaskQueueTest, StopExecutionOnFailure) {
219219
return TaskFinishedResponse::ContinueExecution;
220220
};
221221

222+
const char *Args[] = {"test", nullptr};
222223
for (int i = 0; i < 10; i++) {
223-
const char *Args[] = {"test", nullptr};
224224
TQ.addTask("/bin/echo", Args, llvm::ArrayRef<const char *>(), nullptr, false);
225225
}
226226

0 commit comments

Comments
 (0)