Bug 71292
Summary: | STL / Pthreads - memory leaks | ||
---|---|---|---|
Product: | [Retired] Red Hat Linux | Reporter: | Need Real Name <desertcoder> |
Component: | libg++ | Assignee: | Jakub Jelinek <jakub> |
Status: | CLOSED DUPLICATE | QA Contact: | |
Severity: | high | Docs Contact: | |
Priority: | medium | ||
Version: | 7.3 | ||
Target Milestone: | --- | ||
Target Release: | --- | ||
Hardware: | i386 | ||
OS: | Linux | ||
Whiteboard: | |||
Fixed In Version: | Doc Type: | Bug Fix | |
Doc Text: | Story Points: | --- | |
Clone Of: | Environment: | ||
Last Closed: | 2002-08-12 20:30:57 UTC | Type: | --- |
Regression: | --- | Mount Type: | --- |
Documentation: | --- | CRM: | |
Verified Versions: | Category: | --- | |
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
Cloudforms Team: | --- | Target Upstream Version: | |
Embargoed: |
Description
Need Real Name
2002-08-12 04:45:09 UTC
Sorry. My last post did not completely display the memory leak problem. Here is a better example: //////////////////////////////////////////////////////////////////// // BEGIN: stl_leaker.cpp // //////////////////////////////////////////////////////////////////// #define _GNU_SOURCE #define _REENTRANT #define _THREAD_SAFE #include <pthread.h> #include <iostream> #include <string> #include <unistd.h> using namespace std; void *processClient(void *clientArgs); pthread_attr_t attrDetached; int strMultiplier = 10; int main(int argc, char **argv) { int numThreads = 40; pthread_attr_init(&attrDetached); pthread_attr_setdetachstate(&attrDetached, PTHREAD_CREATE_DETACHED); pthread_t clientThread; //Threads are detached, don't care about handle for ( int threadCount = 0; threadCount <= numThreads; threadCount++ ) { if ( (pthread_create(&clientThread, &attrDetached, processClient, (void *)NULL)) != 0 ) { cout << endl << "ERROR: Could not create client thread."; break; } } sleep(10); //Make sure all detached threads have a chance to return pthread_attr_destroy(&attrDetached); cout << endl << "DONE !" << endl; return 0; } void *processClient(void *clientArgs) { string s1, s2, s3, s4, s5, s6; s1.assign("blah123"); s2.assign("blah123blah123"); s3.assign("blah123blah123blah123"); s4.assign("blah123blah123blah123blah123"); int r = 5 * strMultiplier; for ( int i = 0; i <= r; i++ ) { s5.assign(s1 + s2); s1.assign(s5); } s6.assign(s3 + s2 + s1); return NULL; } //////////////////////////////////////////////////////////////////// // END: stl_leaker.cpp // //////////////////////////////////////////////////////////////////// When strMultiplier = 10, Valgrind reports: ==11851== LEAK SUMMARY: ==11851== definitely lost: 0 bytes in 0 blocks. ==11851== possibly lost: 0 bytes in 0 blocks. ==11851== still reachable: 9528 bytes in 4 blocks. When strMultiplier = 100, Valgrind reports: ==18111== LEAK SUMMARY: ==18111== definitely lost: 3544 bytes in 2 blocks. ==18111== possibly lost: 125904 bytes in 37 blocks. ==18111== still reachable: 45704 bytes in 14 blocks. Can anyone make sense of this? Ken |