If the application ends with the exit(EXIT_FAILURE), does the destructor of the class is called and do the memory cleanup in case the cleanup operations are defined inside the destructor ?
According to the C++ Standard (section 3.6.1 Main function)
4 Terminating the program without leaving the current block (e.g., by calling the function std::exit(int) (18.5)) does not destroy any objects with automatic storage duration (12.4). If std::exit is called to end a program during the destruction of an object with static or thread storage duration, the program has
undefined behavior.
"If the application ends with the exit(EXIT_FAILURE), does the destructor of the class is called and do the memory cleanup in case the cleanup operations are defined inside the destructor ?"
Short answer: for automatic storage, yes.
Though, to expand on this subject a little, this is not always true. Take placement "new" for example: any object created with placement "new" must have its destructor called at the end of the owning pointer's scope; thus, the "new'd" object's destructor must be called before the last remaining pointer to the "new'd" object reaches the end of its residing scope.
In addition, objects allocated with "new" must be "deleted." If you don't call "delete" there will be no destructor call.
@Vlad: Why are you referring to "std::exit( )"? The OP didn't even reference that function. "EXIT_FAILURE" is a integral value defined by the standard to be returned from "main( )" to indicate unsuccessful termination.
Standard wrote:
"Finally, control is returned to the host environment. If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If the value of status is EXIT_FAILURE , an implementation-defined form of the status unsuccessful termination is returned. Otherwise the status returned is implementation-defined."
Agreed. Everything in automatic storage and anything not put into the atexit queue will not be destroyed. Everything in the current block needs to be deallocated and I'd suggest the use of atexit or similar style callback.