realloc-can-shrink.c 329 B

1234567891011121314151617
  1. /* make sure that realloc() can properly shrink buffers */
  2. #include <stdlib.h>
  3. #define LARGE_BUFFER (1 << 20) /* idea is to span a lot of pages */
  4. int main(int argc, char *argv[])
  5. {
  6. int count = 20;
  7. char *ptr = NULL;
  8. while (count--) {
  9. ptr = realloc(ptr, LARGE_BUFFER);
  10. ptr = realloc(ptr, 1);
  11. }
  12. free(ptr);
  13. return 0;
  14. }