From 22624fd35815c68c60d23b92e28f3032ea250697 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 29 Mar 2023 10:38:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=203.2=20realase=20=E5=88=86=E6=94=AF=20lib?= =?UTF-8?q?c-test=20safeunlink=E6=A6=82=E7=8E=87=E6=80=A7=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 方案描述: 1, 修改测试用例流程, 避免free时链表中只有一个结点. fix #I6R6L3 Signed-off-by: wangchen --- libc-test/src/regression/malloc-safe-unlink.c | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/libc-test/src/regression/malloc-safe-unlink.c b/libc-test/src/regression/malloc-safe-unlink.c index 85964d06..c00828ba 100644 --- a/libc-test/src/regression/malloc-safe-unlink.c +++ b/libc-test/src/regression/malloc-safe-unlink.c @@ -27,6 +27,8 @@ static void handler(int s) volatile void *tmp; +#define MALLOC_SIZE 40 + int set_devide_chunk(size_t size) { if (!(tmp = malloc(size))) { @@ -39,10 +41,11 @@ int set_devide_chunk(size_t size) static int child(void) { uintptr_t *c; + uintptr_t *d; uintptr_t *temp; /* Set first dividing chunk */ - if (set_devide_chunk(sizeof(size_t))) + if (set_devide_chunk(MALLOC_SIZE)) return -1; /* @@ -51,14 +54,33 @@ static int child(void) * bin[0] and malloc again. Basically this is heap spray. */ for (int i = 0; i < 512; ++i) { - if (set_devide_chunk(sizeof(size_t))) - return -1; - c = (uintptr_t *)malloc(sizeof(uintptr_t)); + c = (uintptr_t *)malloc(MALLOC_SIZE); if (!c) { t_error("Malloc failed: %s\n", strerror(errno)); return -1; } - free(c); + + if (set_devide_chunk(MALLOC_SIZE)) { + free((void *)c); + return -1; + } + + d = (uintptr_t *)malloc(MALLOC_SIZE); + if (!d) { + t_error("Malloc failed: %s\n", strerror(errno)); + free((void *)c); + return -1; + } + + if (set_devide_chunk(MALLOC_SIZE)) { + free((void *)d); + free((void *)c); + return -1; + } + + free((void *)d); + free((void *)c); + /* exchange the prev and next pointer */ uintptr_t temp = c[0]; c[0] = c[1]; -- GitLab