diff options
| author | Karel Kočí <cynerd@email.cz> | 2025-10-04 12:47:24 +0200 |
|---|---|---|
| committer | Karel Kočí <cynerd@email.cz> | 2025-10-04 12:54:27 +0200 |
| commit | 24e314ca2b56f059f8af28a20b0d2215dbe33eaa (patch) | |
| tree | 12ed017ad24159eb99d2c4b8a50cf5d58af1a0ad /2025-linuxdays/cleanup.c | |
| parent | 58293a7863b4fc2f920bc03008f12f4f6e7ffcc8 (diff) | |
| download | presentations-24e314ca2b56f059f8af28a20b0d2215dbe33eaa.tar.gz presentations-24e314ca2b56f059f8af28a20b0d2215dbe33eaa.tar.bz2 presentations-24e314ca2b56f059f8af28a20b0d2215dbe33eaa.zip | |
Diffstat (limited to '2025-linuxdays/cleanup.c')
| -rw-r--r-- | 2025-linuxdays/cleanup.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/2025-linuxdays/cleanup.c b/2025-linuxdays/cleanup.c new file mode 100644 index 0000000..078114f --- /dev/null +++ b/2025-linuxdays/cleanup.c @@ -0,0 +1,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; +} |
