Skip to content

Commit 9afd166

Browse files
committed
test/cli
1 parent 155f750 commit 9afd166

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

samples/memleak/bad.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <stdlib.h>
22
int main()
33
{
4-
int result;
4+
int result = 0;
55
char *a = malloc(10);
6-
a[0] = 0;
7-
result = a[0];
6+
if (a) {
7+
a[0] = 0;
8+
result = a[0];
9+
}
810
return result;
911
}

samples/memleak/good.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include <stdlib.h>
22
int main()
33
{
4-
int result;
4+
int result = 0;
55
char *a = malloc(10);
6-
a[0] = 0;
7-
result = a[0];
8-
free(a);
6+
if (a) {
7+
a[0] = 0;
8+
result = a[0];
9+
free(a);
10+
}
911
return result;
1012
}

samples/memleak/out.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
samples\memleak\bad.c:8:5: error: Memory leak: a [memleak]
1+
samples\memleak\bad.c:10:5: error: Memory leak: a [memleak]
22
return result;
33
^

0 commit comments

Comments
 (0)