|
From: Dennis L. <pla...@gm...> - 2004-05-26 21:15:35
|
Hi people,
a friend just sent me this here, maybe its worth to add it to FAQ 5 ?
/*
ok, this should give us some errors, shouldnt it ? the vgtest is out of scope
and should be deleted. but gcc stl caches some string data, and therefore
valgrind does not show invalid reads here. To be absolutely shure that it
catches such errors, export GLIBCPP_FORCE_NEW=yes before running the program.
this will cause to delete the string from memory as soon as it is out of scope,
and then valgrind gives us nice errors.
*/
#include <string>
#include <iostream>
using namespace std;
int main ( void )
{
const char * vt;
{
string vgtest("Testing VG");
vt = vgtest.c_str();
}
cout << vt << endl;
}
Carpe quod tibi datum est
|