askhad-apishev / corewar

0 stars 0 forks source link

Malloc error handling #12

Open akaruitori opened 5 years ago

akaruitori commented 5 years ago

Guys, how should we handle cases when malloc() returns NULL? I usually call a function which prints Memory allocation error and then calls exit(), assuming no pointers were lost in program so far. If so, this causes no memory leaks (detected by valgrind).

But there is "still reachable" memory segments left, which is not quite good. So we may create a total free function to call before exit(). Or do something else? We could make the user decide what to do, but we are limited in allowed system functions to use.

srgbl commented 5 years ago

In my opinion we don't need to worry about still reachable blocks. Exit() do all the works for us. While we free memory block right after we don't need it anymore we are in a safe zone.