1:
2:
3:
4:
5:
6: #include <stdlib.h>
7: #include <stdio.h>
8: #include <unistd.h>
9:
10: #ifndef SCALE
11: #define SCALE 100000
12: #endif
13:
14:
15: struct list
16: {
17: struct list *next;
18: };
19:
20:
21: int
22: main ()
23: {
24: struct list *head = NULL;
25: struct list *tail = NULL;
26: struct list *p;
27: long n;
28: int direction;
29:
30: for (direction = 0; direction < 2; direction++)
31: {
32: fprintf (stdout, "allocating\n");
33: fflush (stdout);
34:
35: for (n = 0; n < SCALE; ++n)
36: {
37: p = malloc (sizeof *p);
38: if (NULL == p)
39: {
40: fprintf (stdout, "malloc failed\n");
41: break;
42: }
43: if (direction == 0)
44: {
45: p->next = NULL;
46: if (NULL != tail)
47: tail->next = p;
48: else
49: head = p;
50: tail = p;
51: }
52: else
53: {
54: p->next = head;
55: if (NULL == tail)
56: tail = p;
57: head = p;
58: }
59: }
60:
61: fprintf (stdout, "freeing\n");
62: fflush (stdout);
63:
64: while (NULL != head)
65: {
66: p = head;
67: head = head->next;
68: free (p);
69: }
70:
71: }
72:
73: fprintf (stdout, "done\n");
74: fflush (stdout);
75:
76: return (0);
77: }
78:
79: