Advertisement
teknoraver

goto

Oct 23rd, 2017
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. void func() {
  2.         int sock;
  3.         FILE *file1, *file2;
  4.         char *buf;
  5.  
  6.         sock = socket();
  7.         if (!sock)
  8.                 goto out;
  9.  
  10.         file1 = fopen();
  11.         if (!file1)
  12.                 goto out_sock;
  13.  
  14.         file2 = fopen();
  15.         if (!file2)
  16.                 goto out_file1;
  17.  
  18.         buf = malloc();
  19.         if (!buf)
  20.                 goto out_file2;
  21.  
  22.         /* do things */
  23.  
  24. out_alloc:
  25.         free(buf);
  26. out_file2:
  27.         fclose(file2);
  28. out_file1:
  29.         fclose(file1);
  30. out_sock:
  31.         close(sock);
  32. out:
  33.         return;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement