From 55163114260889d589961a536feae111613e187f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Fri, 18 Oct 2019 23:17:51 +0200 Subject: [PATCH] docs: hacking: extend goto documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace reference to VIR_FREE with g_free and mention the use of g_auto cleanup attributes that eliminate most of label use. Signed-off-by: Ján Tomko Reviewed-by: Daniel P. Berrangé Reviewed-by: Andrea Bolognani --- docs/hacking.html.in | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 030d7818e3..661b262a11 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -1447,11 +1447,16 @@ BAD: single label at the end of the function. It's almost always ok to use this style. In particular, if the cleanup code only involves free'ing memory, then having multiple labels is - overkill. VIR_FREE() and every function named XXXFree() in - libvirt is required to handle NULL as its arg. Thus you can + overkill. g_free() and most of the functions named XXXFree() in + libvirt is required to handle NULL as its arg. This does not + apply to libvirt's public APIs. Thus you can safely call free on all the variables even if they were not yet allocated (yes they have to have been initialized to NULL). This is much simpler and clearer than having multiple labels. + Note that most of libvirt's type declarations can be marked with + either g_autofree or g_autoptr which uses + the compiler's __attribute__((cleanup)) that calls + the appropriate free function when the variable goes out of scope.