Mail Archives: djgpp/1999/12/22/22:29:55
On 22 Dec 99, at 16:45, Chaos wrote:
> Hi there.
>
> In my program, I use several buffers which are dynamically allocated
> (malloc) and also freed during run time (free). For every buffer I'm setting
> condition which looks close to this:
>
> background=malloc(BACKGROUND_BUF_SIZE);
> if(!background)
> {
> fprintf(stderr,"Can't allocate memory for buffor ''background''! \n");
> return 1;
> }
>
> My question is that if the prog reaches that "return 1" (synonim for error)
> does those buffers will be safely deallocated?
Hi again Chaos,
When your program terminates execution the OS (cwsdpmi or
Windoze etc) should handle all the deallocation of the allocated
memory used by that program.
So if that "return 1 " statement causes your program to terminate
(ie if it's in the main() function) and exit to the OS then you can
count on all your previously undeallocated memory being freed.
So IMHO say if you allocate a 4M buffer and exit to the OS without
freeing it the OS should free it and all the other memory that you
process consumed.
However IMHO it might be nice (at least for aesthetic purposes) to
write a error handling function which in your case would cleanup
the deallocating of previously allocated memory and do other things
like restoring hooked interrupt's etc.
> I know I want something very weird ;-)
No way! It's not weird at all.
Kalum
- Raw text -