Advertisement
trideceth12

Goto error recovery

May 16th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. int __init my_init_function(void)
  2. {
  3.     int err;
  4.    
  5.     /* registration takes a pointer and a name */
  6.     err = register_this(ptr1, "skull");
  7.     if (err) goto fail_this;
  8.     err = register_that(ptr2, "skull");
  9.     if (err) goto fail_that;
  10.     err = register_those(ptr3, "skull");
  11.     if (err) goto fail_those;
  12.  
  13.     return 0; /* success */
  14.  
  15.     fail_those: unregister_that(ptr2, "skull");
  16.     fail_that: unregister_this(ptr1, "skull");
  17.     fail_this: return err; /* propagate the error */   
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement