The current VIR_AUTOPTR macro assumes that the struct needs to have a auto-free function auto-generated to call the real free function. The new VIR_AUTOSTRUCT macro allows for structs which already have a free function which takes a pointer to a pointer to the struct and can thus be used directly for auto-cleanup. Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> --- src/util/viralloc.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 2b82096fde..5de18b9ea0 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -614,3 +614,16 @@ void virAllocTestHook(void (*func)(int, void*), void *data); * when the variable goes out of scope. */ #define VIR_AUTOFREE(type) __attribute__((cleanup(virFree))) type + +/** + * VIR_AUTOSTRUCT: + * @type: type of the struct variable to be freed automatically + * + * Macro to automatically free the memory allocated to + * the struct variable declared with it by calling vir$STRUCTFree + * when the variable goes out of scope. + * + * The vir$STRUCTFree function must take a pointer to a pointer + * to the struct. + */ +#define VIR_AUTOSTRUCT(type) __attribute__((cleanup(type ## Free))) type -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list