mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-06 07:37:21 +02:00

Much like the auto-closing helper for file descriptors, add a new auto-free helper that is meant to be used with dynamically allocated memory, a la: autofree char *data = NULL; ... data = malloc(size); When data goes out of scope, cleanup_free will be called with &data, i.e. cleanup_free(&data), which in turn will call free(3) data. In order to work with all types, e.g. 'char *' (resulting in char ** being passed to cleanup_free) or 'int *' (resulting in int ** being passed to cleanup_free), cleanup_free is defined to work with void *, hence the odd-looking cast: void *target = *(void **) ptr.