[libvirt] [PATCH v4 03/31] util: string: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC

Sukrit Bhatnagar skrtbhtngr at gmail.com
Fri Jul 13 17:54:41 UTC 2018


Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in
src/util/viralloc.h, define a new wrapper around an existing
cleanup function which will be called when a variable declared
with VIR_AUTOPTR macro goes out of scope.

Alias virString to (char *) so that the new cleanup macros
can be used for a list of strings (char **).

When a list of strings (virString *) is declared using VIR_AUTOPTR,
the function virStringListFree will be run automatically on it when
it goes out of scope.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr at gmail.com>
Reviewed-by: Erik Skultety <eskultet at redhat.com>
---
 src/util/virstring.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/util/virstring.h b/src/util/virstring.h
index 607ae66..726e02b 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -25,6 +25,9 @@
 # include <stdarg.h>
 
 # include "internal.h"
+# include "viralloc.h"
+
+typedef char *virString;
 
 char **virStringSplitCount(const char *string,
                            const char *delim,
@@ -309,4 +312,6 @@ int virStringParsePort(const char *str,
                        unsigned int *port)
     ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 
+VIR_DEFINE_AUTOPTR_FUNC(virString, virStringListFree)
+
 #endif /* __VIR_STRING_H__ */
-- 
1.8.3.1




More information about the libvir-list mailing list