And I think you misunterstood what King Mir wanted to reach with this bit of code

Free up other resources. If malloc fails, that means you have allocated too much memmory. If you free some of that memmory, you can try malloc again. If it still does not work, your only option is to exit the program. If you have no other resources to free, then you can just quit.