Examples provided by Insure++
Log onto a SLAC Unix machine of a supported architecture. Set up your environment as described above, and locate the examples in
the directory $INSURE/examples/cpp. Copy leak.C to a directory where you have write privilege. Compile and link it using the
insight command, and run it. Also try other examples.
$ cd mytest
$ cp $INSURE/examples/cpp/leak.C .
$ more leak.C
/*
* File: leak.C
*/
#include <string.h>
union S1 {
char *cp;
S1() { cp=new char[10]; }
S1(char *p) {
cp=new char[10];
strcpy(cp,p);
}
S1(S1 &s) {
cp=new char[10];
strcpy(cp,s.cp);
}
void mf(char *p) { strcpy(cp,p); }
};
void foo() {
S1 s1,s2("Hello "),s3=s2;
s1.mf("SADF");
s3.mf("World");
}
int main() {
foo();
return(0);
}
$ insure -g -o foo leak.C
WARNING: /afs/slac/g/babar/package/ParaSoft/Insure++.new/lib.aix4/lib_cSM
was built on morgan10
now executing on firecrown
make sure system libraries match on these hosts
(Note: this last message is a legitimate warning about a possible mismatch between the
shared libraries on the Insure++ build machine and the machine you are currently using.
If both machines use the same version of the operating system, you should not need to
worry.)
$ ./foo
** Insight messages will be written to foo-errs.980312115852 **
main
foo leak.C, 25
S1::S1 [called by non-insight code]
malloc(10) = 0x200048d8
S1::S1 [called by non-insight code]
malloc(10) = 0x20004910
_InSight_strcpy leak.C, 11
S1::S1 [called by non-insight code]
malloc(10) = 0x20004948
_InSight_strcpy leak.C, 15
S1::mf leak.C, 21
_InSight_strcpy leak.C, 17
S1::mf leak.C, 22
_InSight_strcpy leak.C, 17
** TCA log data will be merged with tca.log **
$ more foo-errs.980312115852
[leak.C:23] **LEAK_SCOPE**
>> }
Memory leaked leaving scope: cp
Lost block : 0x20002530 thru 0x20002539 (10 bytes)
cp, allocated at:
operator new() ../new.C
S1::S1() leak.C, 8
foo() leak.C, 20
main() leak.C, 25
Stack trace where the error occurred:
foo() leak.C, 23
main() leak.C, 25
************************** INSURE SUMMARY ************************* v4.0 **
* Program : foo *
* Arguments : *
* Directory : /afs/slac.stanford.edu/u/ec/dragon/ctests/insure/examples/cpp *
* Compiled on : Mar 12, 1998 11:58:32 *
* Run on : Mar 12, 1998 11:58:54 *
* Elapsed time : 00:00:02 *
* Malloc HWM : 310 bytes *
***************************************************************************
PROBLEM SUMMARY - by type
===============
Problem Reported Suppressed
-------------------------------------------------
LEAK_SCOPE 1 2
-------------------------------------------------
TOTAL 1 2
-------------------------------------------------
PROBLEM SUMMARY - by location
===============
LEAK_SCOPE: Memory leaked leaving scope, 1 unique occurrence
3 at leak.C, 23
MEMORY LEAK SUMMARY
===================
8 outstanding memory references for 310 bytes.
Leaks detected during execution
-------------------------------
10 bytes allocated in new.C
operator new() ../new.C
S1::S1() leak.C, 8
foo() leak.C, 20
main() leak.C, 25
Leaks detected at exit
----------------------
10 bytes allocated in new.C
operator new() ../new.C
S1::S1() leak.C, 14
foo() leak.C, 20
main() leak.C, 25
10 bytes allocated in new.C
operator new() ../new.C
S1::S1() leak.C, 10
foo() leak.C, 20
main() leak.C, 25
Outstanding allocated memory
----------------------------
24 bytes allocated in startup.C
__C_runtime_startup() ../startup.C
__start() crt0main.s
64 bytes allocated in new.C
operator new() ../new.C
Iostream_init::Iostream_init() ../cstreams.c
sinit64_x_2flocal_2fattlib_2f2_2e1_2fstream_2fcstreams_2ec() ../cstreams.c
__C_runtime_startup() ../startup.C
__start() crt0main.s
64 bytes allocated in new.C
operator new() ../new.C
Iostream_init::Iostream_init() ../cstreams.c
sinit64_x_2flocal_2fattlib_2f2_2e1_2fstream_2fcstreams_2ec() ../cstreams.c
__C_runtime_startup() ../startup.C
__start() crt0main.s
64 bytes allocated in new.C
operator new() ../new.C
Iostream_init::Iostream_init() ../cstreams.c
sinit64_x_2flocal_2fattlib_2f2_2e1_2fstream_2fcstreams_2ec() ../cstreams.c
__C_runtime_startup() ../startup.C
__start() crt0main.s
64 bytes allocated in new.C
operator new() ../new.C
Iostream_init::Iostream_init() ../cstreams.c
sinit64_x_2flocal_2fattlib_2f2_2e1_2fstream_2fcstreams_2ec() ../cstreams.c
__C_runtime_startup() ../startup.C
__start() crt0main.s
Memory Leak Page
Insure Home Page
[Top of the Page]
|