|
|
984721 |
From 62e22785c706e7ee7f99a6600d4505dc890838ef Mon Sep 17 00:00:00 2001
|
|
|
984721 |
Message-Id: <62e22785c706e7ee7f99a6600d4505dc890838ef@dist-git>
|
|
|
984721 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
984721 |
Date: Fri, 19 Jun 2020 11:43:11 +0200
|
|
|
984721 |
Subject: [PATCH] util: string: Introduce macro for automatic string lists
|
|
|
984721 |
MIME-Version: 1.0
|
|
|
984721 |
Content-Type: text/plain; charset=UTF-8
|
|
|
984721 |
Content-Transfer-Encoding: 8bit
|
|
|
984721 |
|
|
|
984721 |
Similar to VIR_AUTOPTR, VIR_AUTOSTRINGLIST defines a list of strings
|
|
|
984721 |
which will be freed if the pointer is leaving scope.
|
|
|
984721 |
|
|
|
984721 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
984721 |
Reviewed-by: Erik Skultety <eskultet@redhat.com>
|
|
|
984721 |
(cherry picked from commit daefda165b28b399478137c75b5466f865c65be5)
|
|
|
984721 |
|
|
|
984721 |
https://bugzilla.redhat.com/show_bug.cgi?id=1839992
|
|
|
984721 |
|
|
|
984721 |
Conflicts:
|
|
|
984721 |
- src/util/virstring.h - Context. This is RHEL-7.9; did you
|
|
|
984721 |
really think this would be a clean backport? Plenty of
|
|
|
984721 |
patches changed virstring.h in the last two years.
|
|
|
984721 |
|
|
|
984721 |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
984721 |
Message-Id: <c78797a8247bcfb5893bf7b1c2570e98ccda0dd1.1592559697.git.mprivozn@redhat.com>
|
|
|
984721 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
984721 |
---
|
|
|
984721 |
src/libvirt_private.syms | 1 +
|
|
|
984721 |
src/util/virstring.c | 10 ++++++++++
|
|
|
984721 |
src/util/virstring.h | 10 ++++++++++
|
|
|
984721 |
3 files changed, 21 insertions(+)
|
|
|
984721 |
|
|
|
984721 |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
984721 |
index 2a3950fd35..3e5448af94 100644
|
|
|
984721 |
--- a/src/libvirt_private.syms
|
|
|
984721 |
+++ b/src/libvirt_private.syms
|
|
|
984721 |
@@ -2917,6 +2917,7 @@ virStringHasControlChars;
|
|
|
984721 |
virStringIsEmpty;
|
|
|
984721 |
virStringIsPrintable;
|
|
|
984721 |
virStringListAdd;
|
|
|
984721 |
+virStringListAutoFree;
|
|
|
984721 |
virStringListFree;
|
|
|
984721 |
virStringListFreeCount;
|
|
|
984721 |
virStringListGetFirstWithPrefix;
|
|
|
984721 |
diff --git a/src/util/virstring.c b/src/util/virstring.c
|
|
|
984721 |
index 15f367af7c..0f13b6c664 100644
|
|
|
984721 |
--- a/src/util/virstring.c
|
|
|
984721 |
+++ b/src/util/virstring.c
|
|
|
984721 |
@@ -332,6 +332,16 @@ void virStringListFree(char **strings)
|
|
|
984721 |
}
|
|
|
984721 |
|
|
|
984721 |
|
|
|
984721 |
+void virStringListAutoFree(char ***strings)
|
|
|
984721 |
+{
|
|
|
984721 |
+ if (!*strings)
|
|
|
984721 |
+ return;
|
|
|
984721 |
+
|
|
|
984721 |
+ virStringListFree(*strings);
|
|
|
984721 |
+ *strings = NULL;
|
|
|
984721 |
+}
|
|
|
984721 |
+
|
|
|
984721 |
+
|
|
|
984721 |
/**
|
|
|
984721 |
* virStringListFreeCount:
|
|
|
984721 |
* @strings: array of strings to free
|
|
|
984721 |
diff --git a/src/util/virstring.h b/src/util/virstring.h
|
|
|
984721 |
index 607ae66e99..e68b9eec79 100644
|
|
|
984721 |
--- a/src/util/virstring.h
|
|
|
984721 |
+++ b/src/util/virstring.h
|
|
|
984721 |
@@ -53,6 +53,7 @@ int virStringListCopy(char ***dst,
|
|
|
984721 |
const char **src);
|
|
|
984721 |
|
|
|
984721 |
void virStringListFree(char **strings);
|
|
|
984721 |
+void virStringListAutoFree(char ***strings);
|
|
|
984721 |
void virStringListFreeCount(char **strings,
|
|
|
984721 |
size_t count);
|
|
|
984721 |
|
|
|
984721 |
@@ -309,4 +310,13 @@ int virStringParsePort(const char *str,
|
|
|
984721 |
unsigned int *port)
|
|
|
984721 |
ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
|
|
984721 |
|
|
|
984721 |
+/**
|
|
|
984721 |
+ * VIR_AUTOSTRINGLIST:
|
|
|
984721 |
+ *
|
|
|
984721 |
+ * Declares a NULL-terminated list of strings which will be automatically freed
|
|
|
984721 |
+ * when the pointer goes out of scope.
|
|
|
984721 |
+ */
|
|
|
984721 |
+# define VIR_AUTOSTRINGLIST \
|
|
|
984721 |
+ __attribute__((cleanup(virStringListAutoFree))) char **
|
|
|
984721 |
+
|
|
|
984721 |
#endif /* __VIR_STRING_H__ */
|
|
|
984721 |
--
|
|
|
984721 |
2.27.0
|
|
|
984721 |
|