aboutsummaryrefslogtreecommitdiff
path: root/2025-linuxdays/cleanup.c
diff options
context:
space:
mode:
Diffstat (limited to '2025-linuxdays/cleanup.c')
-rw-r--r--2025-linuxdays/cleanup.c16
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;
+}