Why memory leaks?


B

Billy Patton

I have this test code:

{
String s("123");
OK(s.Len() == 3);


OK is a define to print __LINE__ and increment a test_count and a failure count

String is built using std::string as the memory namager for the string.

I have the following method:
This one produces no errors with purify.
size_t String::Len(void)
{
if (str.empty()) return 0;
return strlen(str.c_str());
// return str.size();
}

size_t String::Len(void)
{
return str.size();
}

THe routine above produces the one above. The folowing is from purify:
Finished test ( 1 error, 0 leaked bytes)
Purify instrumented SunOS/32/test (pid 15865 at Thu May 26 07:32:17 2005)
UMR: Uninitialized memory read
This is occurring while in:
__big_float_times_power [libc.a]
__binary_to_decimal_fraction [libc.a]
_unpacked_to_decimal_two [libc.a]
__k_double_to_decimal [libc.a]
double_to_decimal [libc.a]
econvert [libc.a]
Reading 2 bytes from 0xffbedfda on the stack.
Address 0xffbedfda is 1086 bytes below frame pointer in function
__k_double_to_decimal.
Current file descriptors in use: 5
Memory leaked: 0 bytes (0%); potentially leaked: 0 bytes (0%)
Purify Heap Analysis (combining suppressed and unsuppressed blocks)
Blocks Bytes
Leaked 0 0
Potentially Leaked 1 8200
In-Use 0 0
----------------------------------------
Total Allocated 1 8200
Program exited with status code 0.
* Basic memory usage (including Purify overhead):
2566822 code
1947676 data/bss
16388 heap (peak use)
3040 stack


It appears that std::string::size is causing the error.

I use gcc 3.4.2 on a solaris 8 box.
purify.sol.2002a.06.00
Since IBM bought Purify we don't see updates/new releases

___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, (e-mail address removed)
 
Ad

Advertisements

B

Billy Patton

I have this test code:

{
String s("123");
OK(s.Len() == 3);


OK is a define to print __LINE__ and increment a test_count and a failure
count

String is built using std::string as the memory namager for the string.

I have the following method:
This one produces no errors with purify.
size_t String::Len(void)
{
if (str.empty()) return 0;
return strlen(str.c_str());
// return str.size();
}

size_t String::Len(void)
{
return str.size();
}

THe routine above produces the one above. The folowing is from purify:
Finished test ( 1 error, 0 leaked bytes)
Purify instrumented SunOS/32/test (pid 15865 at Thu May 26 07:32:17
2005)
UMR: Uninitialized memory read
This is occurring while in:
__big_float_times_power [libc.a]
__binary_to_decimal_fraction [libc.a]
_unpacked_to_decimal_two [libc.a]
__k_double_to_decimal [libc.a]
double_to_decimal [libc.a]
econvert [libc.a]
Reading 2 bytes from 0xffbedfda on the stack.
Address 0xffbedfda is 1086 bytes below frame pointer in function
__k_double_to_decimal.
Current file descriptors in use: 5
Memory leaked: 0 bytes (0%); potentially leaked: 0 bytes (0%)
Purify Heap Analysis (combining suppressed and unsuppressed blocks)
Blocks Bytes
Leaked 0 0
Potentially Leaked 1 8200
In-Use 0 0
----------------------------------------
Total Allocated 1 8200
Program exited with status code 0.
* Basic memory usage (including Purify overhead):
2566822 code
1947676 data/bss
16388 heap (peak use)
3040 stack


It appears that std::string::size is causing the error.

I use gcc 3.4.2 on a solaris 8 box.
purify.sol.2002a.06.00
Since IBM bought Purify we don't see updates/new releases

___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/ Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, (e-mail address removed)

I tried this code on the Linux box with
PurifyPlus.2003a.06.13/i386_linux2/bin/purify
and had no leaks?????
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
std::string s("abc");
size_t len = s.size();
cout << "len = " << len << "\n";
return 0;
}


___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, (e-mail address removed)
 
B

Billy Patton

I have this test code:

{
String s("123");
OK(s.Len() == 3);


OK is a define to print __LINE__ and increment a test_count and a failure
count

String is built using std::string as the memory namager for the string.

I have the following method:
This one produces no errors with purify.
size_t String::Len(void)
{
if (str.empty()) return 0;
return strlen(str.c_str());
// return str.size();
}

size_t String::Len(void)
{
return str.size();
}

THe routine above produces the one above. The folowing is from purify:
Finished test ( 1 error, 0 leaked bytes)
Purify instrumented SunOS/32/test (pid 15865 at Thu May 26 07:32:17
2005)
UMR: Uninitialized memory read
This is occurring while in:
__big_float_times_power [libc.a]
__binary_to_decimal_fraction [libc.a]
_unpacked_to_decimal_two [libc.a]
__k_double_to_decimal [libc.a]
double_to_decimal [libc.a]
econvert [libc.a]
Reading 2 bytes from 0xffbedfda on the stack.
Address 0xffbedfda is 1086 bytes below frame pointer in function
__k_double_to_decimal.
Current file descriptors in use: 5
Memory leaked: 0 bytes (0%); potentially leaked: 0 bytes (0%)
Purify Heap Analysis (combining suppressed and unsuppressed blocks)
Blocks Bytes
Leaked 0 0
Potentially Leaked 1 8200
In-Use 0 0
----------------------------------------
Total Allocated 1 8200
Program exited with status code 0.
* Basic memory usage (including Purify overhead):
2566822 code
1947676 data/bss
16388 heap (peak use)
3040 stack


It appears that std::string::size is causing the error.

I use gcc 3.4.2 on a solaris 8 box.
purify.sol.2002a.06.00
Since IBM bought Purify we don't see updates/new releases

___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/ Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, (e-mail address removed)

I tried this code on the Linux box with
PurifyPlus.2003a.06.13/i386_linux2/bin/purify
and had no leaks?????
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
std::string s("abc");
size_t len = s.size();
cout << "len = " << len << "\n";
return 0;
}


___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/ Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, (e-mail address removed)

Must have been the older oversion of Purify on solaris. Ran with the
PurifyPlus 2003 version on Linux and leak went away.

As that great poet/philosopher Alf one said "go figure" :)


___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, (e-mail address removed)
 
V

Victor Bazarov

Billy said:

Do you think you could at least trim your *own* signatures when you reply
to yourself?

And, please, keep in mind that Purify is not topical here. Talk to their
Tech Support about any issues you have with that product. This is
a _language_ newsgroup, please limit your posts to _language_ topics.

V
 
Ad

Advertisements

M

Mark P

Billy said:
I have this test code:

{
String s("123");
OK(s.Len() == 3);
[snip]

It's fairly well known that STL classes and purify sometimes interact
badly and the latter can be confused by the former. In part this is
because STL objects may do nonobvious things with their memory,
ostensibly for optimization purposes, such as not freeing memory
promptly and reserving it for later allocations. You should look at the
purify website as I believe this is discussed there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top