/
niceSOFT
/
valgrind
Обзор
Документация
Войти
/
niceSOFT
/
valgrind
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
drd/tests/memory_allocation.c
37 строк
821 B
Paul Floyd
Bug 436413 - Warn about realloc of size zero
10 мар 2023, 23:55
10 мар 2023, 23:55
50bded7
Код
Авторство
О чём код?
/** * @brief Repeatedly allocate and free memory. Tests whether drd really frees * memory allocated by a client. See also * http://bugs.kde.org/show_bug.cgi?id=161036. */ #include <assert.h> #include <stdlib.h> int main() { int i; void* p; for (i = 0; i < 100000; i++) free(malloc(40960)); for (i = 0; i < 100000; i++) { p = realloc(NULL, 40960); p = realloc(p, 50000); p = realloc(p, 40000); p = realloc(p, 0); /* * glibc returns a NULL pointer when the size argument passed to realloc() * is zero, while Darwin's C library returns a non-NULL pointer. Both are * allowed by POSIX. * * Other platforms also tend not to free. To make things simpler just * free it if it is not NULL. */ if (p) free(p); } return 0; }