main
|
Last change
on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
646 bytes
|
| 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.