Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » exit() -> heap leaks detected.
exit() -> heap leaks detected. [message #17996] Fri, 05 September 2008 22:23 Go to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Why does exit() cause a heap leak when Vector class has items?

Example:
CONSOLE_APP_MAIN
{	
	Vector<String> v1;
	v1.Add("hello");
	exit(1);
	
}


Re: exit() -> heap leaks detected. [message #17997 is a reply to message #17996] Fri, 05 September 2008 23:00 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Maybe "exit" does not call some destructors? Try to exit cleanly.
To set the exit value with clean finish you can use: (to see if it helps)
 	UPP::SetExitCode( 1 );


BTW, what version of UPP and what compiler?
The leak detection should work ok just with the MSC. ( Sad )

[Updated on: Fri, 05 September 2008 23:00]

Report message to a moderator

Re: exit() -> heap leaks detected. [message #17998 is a reply to message #17997] Fri, 05 September 2008 23:15 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
SetExitCode() does not perform the exit operation also.

My compiler is Linux GCC 4.1.3, but it also happens with MSC8.
Upp SVN.324

I first encountered it when trying to use another C++ library that called exit(). I can control the exit path on my application, but I don't want to have to modify other libs. I partially wrote the command line processor package for this reason.

[Updated on: Fri, 05 September 2008 23:16]

Report message to a moderator

Re: exit() -> heap leaks detected. [message #17999 is a reply to message #17998] Fri, 05 September 2008 23:44 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
captainc wrote on Fri, 05 September 2008 23:15

SetExitCode() does not perform the exit operation also.


I was sort of trying to write that, but reading my post again ... and it's far from obvious.

Well, I was unable to make leak detection work in 2008.1 with GCC (MINGW too). I mean, I forced it to run and collect data, but the init of U++ itself did leak always. Maybe the SVN version is fixed a bit in this manner?
I can't follow the SVN, I need very stable code base for my purposes, and I don't have spare time to try it in other directory right now. :/

Are you sure the Vector is leaking? When you remove the Vector stuff, does it leak or not? (and you can use the memory breakpoint feature to break at the leaking alloc ... although debugging with GCC is total pain, I rather add some LOG here/there to avoid debugging with U++, it's so bad. :/

[Updated on: Fri, 05 September 2008 23:46]

Report message to a moderator

Re: exit() -> heap leaks detected. [message #18000 is a reply to message #17999] Sat, 06 September 2008 00:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I think it is quite obvious:

How do you expect the Vector destructor (of *local* variable) being called? The control never gets to the end of block....

The moral of the story is: never call "exit" in C++ and expect clean exit...

Mirek
Re: exit() -> heap leaks detected. [message #18001 is a reply to message #18000] Sat, 06 September 2008 00:39 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
From definition of exit function:
Quote:

Terminates the process normally, performing the regular cleanup for terminating processes.

First, all functions registered by calls to atexit are executed in the reverse order of their registration. Then, all streams are closed and the temporary files deleted, and finally the control is returned to the host environment.

This is why I have been confused. Is the definition not consistent with the actions? I guess I did not research it enough... neither did a few library authors!
Re: exit() -> heap leaks detected. [message #18002 is a reply to message #18001] Sat, 06 September 2008 00:43 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Seems with Upp, the right course of action would be to:
SetExitCode(1);
return;

instead of using exit(1);

As we are really in function ConsoleMainFn_(), which is called from main().
hmm, but this doesn't solve library issue.

[Updated on: Sat, 06 September 2008 00:45]

Report message to a moderator

Re: exit() -> heap leaks detected. [message #18003 is a reply to message #18001] Sat, 06 September 2008 08:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
captainc wrote on Fri, 05 September 2008 18:39

From definition of exit function:
Quote:

Terminates the process normally, performing the regular cleanup for terminating processes.

First, all functions registered by calls to atexit are executed in the reverse order of their registration. Then, all streams are closed and the temporary files deleted, and finally the control is returned to the host environment.

This is why I have been confused. Is the definition not consistent with the actions? I guess I did not research it enough... neither did a few library authors!


Well, global destructors are registred via atexit (usually, it is). Anyway, "exit" never returns, means nothing can be called at the end of block.

OTOH, as system usually performs necessarry cleanup (closing file handles etc...), I can see that some C++ library calls exit, not caring about leaks. But that is not really correct in my book.

Mirek
Re: exit() -> heap leaks detected. [message #18004 is a reply to message #18002] Sat, 06 September 2008 08:41 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
captainc wrote on Fri, 05 September 2008 18:43

Seems with Upp, the right course of action would be to:
SetExitCode(1);
return;

instead of using exit(1);

As we are really in function ConsoleMainFn_(), which is called from main().
hmm, but this doesn't solve library issue.


IMO, you cannot solve the problem without altering the library code (maybe you should complain to the author Smile

Possible fix is to use exception handling - define something like "struct Exit", throw it instead of "exit" and catch in main, then SetExitCde(1), return.

Mirek
Re: exit() -> heap leaks detected. [message #18010 is a reply to message #18004] Sat, 06 September 2008 13:25 Go to previous message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Quote:

IMO, you cannot solve the problem without altering the library code (maybe you should complain to the author

Yeah, I really don't like the fact that they call exit instead of throwing an exception. I would rather alter it or find some other way.
Previous Topic: U++ suggestions
Next Topic: RectTracker & MaxRect
Goto Forum:
  


Current Time: Thu Mar 28 17:14:46 CET 2024

Total time taken to generate the page: 0.01308 seconds