File: tst-trim1.c

package info (click to toggle)
glibc 2.28-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, experimental, sid
  • size: 271,788 kB
  • sloc: ansic: 1,008,637; asm: 259,607; makefile: 11,271; sh: 10,477; python: 6,910; cpp: 4,992; perl: 2,258; awk: 2,005; yacc: 290; pascal: 182; sed: 73
file content (56 lines) | stat: -rw-r--r-- 962 bytes parent folder | download | duplicates (25)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 10000

static void *arr[N];

static int
do_test (void)
{
  for (int i = 0; i < N; ++i)
    {
      size_t size = random () % 16384;

      if ((arr[i] = malloc (size)) == NULL)
	{
	nomem:
	  puts ("not enough memory");
	  return 0;
	}

      memset (arr[i], size, size);
    }

  void *p = malloc (256);
  if (p == NULL)
    goto nomem;
  memset (p, 1, 256);

  puts ("==================================================================");

  for (int i = 0; i < N; ++i)
    if (i % 13 != 0)
      free (arr[i]);

  puts ("==================================================================");

  malloc_trim (0);

  puts ("==================================================================");

  p = malloc (30000);
  if (p == NULL)
    goto nomem;

  memset (p, 2, 30000);

  malloc_trim (0);

  return 0;
}

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"