Skip to content

Instantly share code, notes, and snippets.

@PttCodingMan
Last active February 10, 2023 09:19
Show Gist options
  • Save PttCodingMan/21cfbae514cab93d41ee1980a9de6de6 to your computer and use it in GitHub Desktop.
Save PttCodingMan/21cfbae514cab93d41ee1980a9de6de6 to your computer and use it in GitHub Desktop.
C language function example to avoid memory leak using goto.
int func(....){
// declare variable here
// check input here
if(pointer == NULL) goto end;
if(!run_condition) goto end;
// do something
if(!run_condition) goto end;
end:
// free pointers here
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment