SHARE
TWEET

goto

a guest May 24th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     FILE *file = fopen("test.txt", "r");
  7.     if (!file)
  8.         goto error1;
  9.  
  10.     char **names = malloc(100);
  11.     if (!names)
  12.         goto error2;
  13.    
  14.     for (size_t i = 0; i < 10; i++)
  15.     {
  16.         char *name = malloc(32);
  17.         if (!name)
  18.             goto error3;
  19.         names[i] = name;
  20.     }
  21.  
  22.     ...
  23.  
  24.  
  25.  
  26. error3:    
  27.     if(names)
  28.         free(names);
  29. error2:    
  30.     for (size_t i = 0; i < 10; i++)
  31.     {
  32.         if(names[i])
  33.             free(names[i]);
  34.     }
  35. error1:
  36.     if (file)
  37.         free(file);
  38.  
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top