Skip to content

Instantly share code, notes, and snippets.

@YukiSakamoto
Created August 28, 2012 16:04
Show Gist options
  • Save YukiSakamoto/3499507 to your computer and use it in GitHub Desktop.
Save YukiSakamoto/3499507 to your computer and use it in GitHub Desktop.
attribute(cleanup) sample
#include <stdio.h>
#include <stdlib.h>
#define cleanup_free_scope __attribute__((cleanup(my_free)))
#define cleanup_print_scope __attribute__((cleanup(my_print_int)))
void my_print_int(int *i)
{
printf("argument = %d\n", *i);
}
void my_free(void **p)
{
printf("%p was freed.\n", p);
free(*p);
}
int main(void)
{
void *p1 cleanup_free_scope = malloc(1000);
void *p2 cleanup_free_scope = malloc(128);
int val cleanup_print_scope = 10289;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment