#include #include #include "defer.h" int main() { int n; printf("Allocate this much bytes: "); scanf("%d", &n); void *ram = malloc(n); defer { free(ram); printf("%d bytes freed\n", n); }; unsigned char cs = 0; unsigned char *bytes = ram; for(int i = 0; i < n; ++i) { cs += bytes[i]; } printf("Checksum of found bytes: %d\n", (int) cs); // exit(0); // This does not release resources! return 0; }