mirror of
				https://github.com/FeralInteractive/gamemode.git
				synced 2025-10-31 14:04:14 +01:00 
			
		
		
		
	common: add autofree helper
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.
This commit is contained in:
		| @@ -39,3 +39,4 @@ POSSIBILITY OF SUCH DAMAGE. | ||||
|  * a specific call to the function the linker will expect an definition. | ||||
|  */ | ||||
| extern inline void cleanup_close(int *fd); | ||||
| extern inline void cleanup_free(void *ptr); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Christian Kellner
					Christian Kellner