5 ms·
Can you explain what you mean by use of gotos for memory management?
by Peaker 15y ago
Can you explain what you mean by use of gotos for memory management?
- sjs 15y agoHere's an example: void do_stuff(char *name) { char *my_name = strdup(name); if (condition_signalling_no_work()) goto done; if (do_something_with(my_name)) goto done; ... done: free(my_name); return; } If it helps think of it as a finally block. The function does some things and no matter what it has to run that block at the end.
- Peaker 15y agoAh, so for resource cleanup in general, not memory management in particular.