PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Exception + string = Speicherleck?


Gast
2006-03-29, 15:55:15
Hi,

folgender Code erzeugt ein Speicherleck:

try
{
string s="s";
throw 2;
}
catch (int e)
{
cout << e << endl;;
}


==22686== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 23 from 1)
==22686== malloc/free: in use at exit: 640 bytes in 1 blocks.
==22686== malloc/free: 2 allocs, 1 frees, 724 bytes allocated.
==22686== For counts of detected errors, rerun with: -v
==22686== searching for pointers to 1 not-freed blocks.
==22686== checked 119424 bytes.
==22686==
==22686== LEAK SUMMARY:
==22686== definitely lost: 0 bytes in 0 blocks.
==22686== possibly lost: 0 bytes in 0 blocks.
==22686== still reachable: 640 bytes in 1 blocks.
==22686== suppressed: 0 bytes in 0 blocks.
==22686== Reachable blocks (those to which a pointer was found) are not shown.
==22686== To see them, rerun with: --show-reachable=yes

Folgender Code ist sauber:

try
{
//string s="s";
throw 2;
}
catch (int e)
{
cout << e << endl;;
}


==22976== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 23 from 1)
==22976== malloc/free: in use at exit: 0 bytes in 0 blocks.
==22976== malloc/free: 1 allocs, 1 frees, 84 bytes allocated.
==22976== For counts of detected errors, rerun with: -v
==22976== No malloc'd blocks -- no leaks are possible.

Was ist da los? Irgendetwas passiert mit dem Speicher für den String. Wie kann man das beheben?

Gast
2006-03-29, 16:24:38
Kann definitiv nicht sein. Muss an Compiler(einstellung), deiner STL-Implementierung oder an dem Leakdetector liegen.

Aqualon
2006-03-29, 18:01:56
http://valgrind.org/docs/manual/faq.html#faq.reports

Aqua

Gast
2006-03-30, 10:17:07
Alles klar, danke.