File: t5.c

package info (click to toggle)
zmailer 2.99.51.52pre3-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 16,596 kB
  • ctags: 7,422
  • sloc: ansic: 90,470; sh: 3,608; makefile: 2,784; perl: 1,585; python: 115; awk: 22
file content (31 lines) | stat: -rw-r--r-- 753 bytes parent folder | download | duplicates (3)
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
/*
 * posted to the net by someone who asked "Why is this causing malloc to
 * dump core!  Modified slightly to free the pointers, which causes my
 * debugging malloc to find the bug.  Turning on malloc_debug(2) also
 * spots the problem.
 */
#include <stdio.h>

int
main()
{
        char *p[3], wd[128];
        int  len, i;
        char *malloc();
        int      strlen();

        strcpy(wd,"test");

        for (i=0; i<3; i++) {
                len = strlen(wd);
                if ((p[i] = malloc(len)) == NULL) {
                        printf("ERROR: malloc failed\n");
                        exit(-1);
                }
                else
                        strcpy(p[i],wd);
        }
	for(i=0; i < 3; i++)
		free(p[i]);
	return 0;
}