I would like a simple example on how to use the Leaks tool.
see:#include <iostream>
int main (int argc, char * const argv[]) {
char *buf = new char[100];
sprintf(buf, "Hello, World!\n");
// insert code here...
std::cout << buf;
return 0;
}
the code above(simple example) should leak the pointer allocated on开发者_如何学运维 *buf, right?
with valgrind I would find this very easy after a run but I just can't find how to do this on the Leaks program I tried to put sleep(60) but it is still not friendly to me...thanks,
JonathanI've found that Leaks doesn't work all that well with command line applications that exit quickly. I would suggest adding a sleep()
like you've done, but add one before the main program logic, and again at the end, so that Leaks is likely to sample the leaked state.
int main() {
sleep(20); // 20s may be enough
{
// do leaky operations, then local variables will go out of scope
}
sleep(20);
}
精彩评论