does strdup cause memory leakage?
Code:
string str("/usr/bin/");
string str2 = string(dirname(strdup(str.c_str())));
cout<<str2<<endl;
I modified the code as:
Code:
string str("/usr/bin/");
char * tmp = strdup(str.c_str());
string str2 = string(dirname( tmp ));
delete(tmp);
Using valgrind it reports:
==18859== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 17 from 1)
==18859== malloc/free: in use at exit: 0 bytes in 0 blocks.
==18859== malloc/free: 3 allocs, 3 frees, 49 bytes allocated.
==18859== For counts of detected errors, rerun with: -v
==18859== No malloc'd blocks -- no leaks are possible.