main
test-branch
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * This example demonstrates the checking of memory leak, i.e.,
|
|---|
| 3 | * when a dynamic scope becomes unreachable, its heap should
|
|---|
| 4 | * be cleaned up.
|
|---|
| 5 | *
|
|---|
| 6 | * Command line execution: civl verify memoryLeak.cvl
|
|---|
| 7 | */
|
|---|
| 8 | #include<civlc.cvh>
|
|---|
| 9 |
|
|---|
| 10 | void process(){
|
|---|
| 11 | int * p = (int *) $malloc($here, sizeof(int));
|
|---|
| 12 | double * q;
|
|---|
| 13 |
|
|---|
| 14 | *p = 10;
|
|---|
| 15 | for(int i = 0; i < 5; i++){
|
|---|
| 16 | q = (double *) $malloc($here, sizeof(double));
|
|---|
| 17 | *q = i + i*0.1;
|
|---|
| 18 | $free(q);
|
|---|
| 19 | }
|
|---|
| 20 | //$free(p); // not freeing p, memory leak detected here.
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | void main(){
|
|---|
| 24 | $proc p = $spawn process();
|
|---|
| 25 | double * q = (double *) $malloc($here, sizeof(double));
|
|---|
| 26 |
|
|---|
| 27 | *q = 1.1;
|
|---|
| 28 | $wait(p);
|
|---|
| 29 | $free(q);
|
|---|
| 30 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.