Skip to content

Commit 309bb1e

Browse files
authored
[scudo] Fix c wrappers double free test. (#148066)
The previous test simply tried to double free the pointer in the EXPECT_DEATH macro. Unfortunately, the gtest infrastructure can allocate a pointer that happens to be the previously freed pointer. Thus the free doesn't fail since the spawned process does not attempt to free all of the pointers allocated in the original test. NOTE: Scudo should be checked to make sure that the TSD is not always returning pointers in the same order they are freed. Although this appears to be a problem with a program that only does a small number of allocations.
1 parent 2e53a68 commit 309bb1e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,19 @@ TEST_F(ScudoWrappersCDeathTest, Malloc) {
175175

176176
free(P);
177177
verifyDeallocHookPtr(P);
178-
EXPECT_DEATH(free(P), "");
178+
179+
// Verify a double free causes an abort.
180+
// Don't simply free(P) since EXPECT_DEATH will do a number of
181+
// allocations before creating a new process. There is a possibility
182+
// that the previously freed P is reused, therefore, in the new
183+
// process doing free(P) is not a double free.
184+
EXPECT_DEATH(
185+
{
186+
void *Ptr = malloc(Size);
187+
free(Ptr);
188+
free(Ptr);
189+
},
190+
"");
179191

180192
P = malloc(0U);
181193
EXPECT_NE(P, nullptr);

0 commit comments

Comments
 (0)