Re:Dangerous Embedded C Coding Standard Rules (2011)
by anywherenotes on Monday December 30, 2013 @02:20PM
(#6986262)
The code I used is more like this:
And RETURN_ERROR is defined as:
[ Parent
| on HN ]
Re:Dangerous Embedded C Coding Standard Rules (2011)
by nitrogen on Monday December 30, 2013 @04:24PM
(#6987065)
The approach I use, and that used many places in the Linux kernel, is to use goto for error handling:
if(failure_1) {
goto error;
}
if(failure_2) {
goto error;
}
// Do stuff
return 0;
error:
if(f != NULL) {
fclose(f);
}
if(s != NULL) {
free(s);
}
return -1;