improve write-after-free tests

This commit is contained in:
Daniel Micay 2018-09-06 23:48:47 -04:00
parent 3751b85e47
commit 918f0d3302
2 changed files with 9 additions and 5 deletions

View File

@ -1,4 +1,3 @@
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -9,6 +8,6 @@ int main(void) {
return 1; return 1;
} }
free(p); free(p);
memset(p, 'a', 128 * 1024); p[64 * 1024 + 1] = 'a';
return 0; return 0;
} }

View File

@ -1,14 +1,19 @@
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
__attribute__((optimize(0))) __attribute__((optimize(0)))
int main(void) { int main(void) {
char *p = malloc(16); char *p = malloc(128);
if (!p) { if (!p) {
return 1; return 1;
} }
free(p); free(p);
memset(p, 'a', 16);
p[65] = 'a';
// trigger reuse of the allocation
for (size_t i = 0; i < 100000; i++) {
free(malloc(128));
}
return 0; return 0;
} }