Skip to content

Commit c31a761

Browse files
authored
Add files via upload
1 parent b7de370 commit c31a761

File tree

2 files changed

+85
-8
lines changed

2 files changed

+85
-8
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
| test.c:9:8:9:10 | buf | This pointer may be cleared again later. |
2-
| test.c:19:26:19:29 | buf1 | This pointer may be cleared again later. |
1+
| test.c:11:16:11:18 | buf | This pointer may have already been cleared in the line 10. |
2+
| test.c:18:8:18:10 | buf | This pointer may have already been cleared in the line 17. |
3+
| test.c:57:8:57:10 | buf | This pointer may have already been cleared in the line 55. |
4+
| test.c:78:8:78:10 | buf | This pointer may have already been cleared in the line 77. |
Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,96 @@
11
typedef unsigned long size_t;
22
void *malloc(size_t size);
33
void free(void *ptr);
4+
#define NULL 0
45

56
void workFunction_0(char *s) {
67
int intSize = 10;
78
char *buf;
89
buf = (char *) malloc(intSize);
9-
free(buf); // BAD
10-
if(buf) free(buf);
10+
free(buf); // GOOD
11+
if(buf) free(buf); // BAD
1112
}
1213
void workFunction_1(char *s) {
14+
int intSize = 10;
15+
char *buf;
16+
buf = (char *) malloc(intSize);
17+
free(buf); // GOOD
18+
free(buf); // BAD
19+
}
20+
void workFunction_2(char *s) {
21+
int intSize = 10;
22+
char *buf;
23+
buf = (char *) malloc(intSize);
24+
free(buf); // GOOD
25+
buf = NULL;
26+
free(buf);
27+
}
28+
void workFunction_3(char *s) {
29+
int intSize = 10;
30+
char *buf;
31+
int intFlag;
32+
buf = (char *) malloc(intSize);
33+
if(buf[1]%5) {
34+
free(buf);
35+
buf = NULL;
36+
}
37+
free(buf);
38+
}
39+
void workFunction_4(char *s) {
40+
int intSize = 10;
41+
char *buf;
42+
char *tmpbuf;
43+
tmpbuf = (char *) malloc(intSize);
44+
buf = (char *) malloc(intSize);
45+
free(buf); // GOOD
46+
buf = tmpbuf;
47+
free(buf); // GOOD
48+
}
49+
void workFunction_5(char *s) {
50+
int intSize = 10;
51+
char *buf;
52+
int intFlag;
53+
buf = (char *) malloc(intSize);
54+
if(intFlag) {
55+
free(buf);
56+
}
57+
free(buf); // BAD
58+
}
59+
void workFunction_6(char *s) {
60+
int intSize = 10;
61+
char *buf;
62+
char *tmpbuf;
63+
int intFlag;
64+
tmpbuf = (char *) malloc(intSize);
65+
buf = (char *) malloc(intSize);
66+
if(intFlag) {
67+
free(buf);
68+
buf = tmpbuf;
69+
}
70+
free(buf);
71+
}
72+
void workFunction_7(char *s) {
73+
int intSize = 10;
74+
char *buf;
75+
char *buf1;
76+
buf = (char *) malloc(intSize);
77+
buf1 = (char *) realloc(buf,intSize*4);
78+
free(buf); // BAD
79+
}
80+
void workFunction_8(char *s) {
81+
int intSize = 10;
82+
char *buf;
83+
char *buf1;
84+
buf = (char *) malloc(intSize);
85+
buf1 = (char *) realloc(buf,intSize*4);
86+
if(!buf1)
87+
free(buf); // GOOD
88+
}
89+
void workFunction_9(char *s) {
1390
int intSize = 10;
1491
char *buf;
1592
char *buf1;
1693
buf = (char *) malloc(intSize);
17-
buf1 = (char *) realloc(buf,intSize*2);
18-
if(buf) free(buf); // GOOD
19-
buf = (char *) realloc(buf1,intSize*4); // BAD
20-
free(buf1);
94+
if(!(buf1 = (char *) realloc(buf,intSize*4)))
95+
free(buf); // GOOD
2196
}

0 commit comments

Comments
 (0)