aboutsummaryrefslogtreecommitdiff
path: root/2025-linuxdays/cleanup.c
blob: 078114f2f682e59116533e3385a2449408a3aef7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <assert.h>
#include <stdbit.h>
#include <stdio.h>
#include <stdlib.h>

static void _free(char **ptr) {
  printf("Freeing %p=%p\n", ptr, *ptr);
  free(*ptr);
}

int main(int argc, char *argv[]) {
  [[gnu::cleanup(_free)]] char *buf = malloc(18);
  [[gnu::cleanup(_free)]] char *null = NULL;
  printf("Pointers: %p=%p %p=%p\n", &buf, buf, &null, null);
  return 0;
}