Skip to content

Instantly share code, notes, and snippets.

@mu8086
Created June 12, 2022 12:28
Show Gist options
  • Save mu8086/c3316530397926647a4f2c12936b3a34 to your computer and use it in GitHub Desktop.
Save mu8086/c3316530397926647a4f2c12936b3a34 to your computer and use it in GitHub Desktop.
[C] variadic free function
void doFree(void * allocate, ...) {
void *target = allocate;
va_list args;
va_start(args, allocate);
while (target != NULL) {
free(target);
target = va_arg(args, void *);
}
va_end(args);
}
void main(void) {
char *a = (char *) malloc(sizeof(char));
int *b = (int *) malloc(sizeof(int));
doFree(a, b, NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment