(Reimplement libnbd commit c7ff70101e8c, "convert
string_vector_(iter(free) + reset()) to string_vector_empty()",
2023-02-28.)
Convert the 5 string_vector_(iter(free) + reset()) call sites mentioned
previously to string_vector_empty().
Note that the converted code performs more cleanup steps in some cases
than strictly necessary, but the extra work is harmless, and arguably
beneficial for clarity / consistency.
Also note that the CLEANUP_FREE_*() macros remain unique to nbdkit; libnbd
does not use __attribute__((cleanup)), per libnbd commit f306e231d294
("common/utils: Add extensible string, based on vector", 2022-03-12).
Signed-off-by: Laszlo Ersek <lersek(a)redhat.com>
---
common/utils/string-vector.h | 9 +--------
server/public.c | 3 +--
common/utils/environ.c | 3 +--
plugins/iso/iso.c | 3 +--
plugins/split/split.c | 3 +--
5 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/common/utils/string-vector.h b/common/utils/string-vector.h
index 40446008b6a9..8245c5292e1a 100644
--- a/common/utils/string-vector.h
+++ b/common/utils/string-vector.h
@@ -41,13 +41,6 @@ DEFINE_POINTER_VECTOR_TYPE (string_vector, char *);
/* This frees both the array and the strings. */
#define CLEANUP_FREE_STRING_VECTOR \
- __attribute__ ((cleanup (cleanup_free_string_vector)))
-
-static void __attribute__ ((__unused__))
-cleanup_free_string_vector (string_vector *v)
-{
- string_vector_iter (v, (void*)free);
- string_vector_reset (v);
-}
+ __attribute__ ((cleanup (string_vector_empty)))
#endif /* STRING_VECTOR_H */
diff --git a/server/public.c b/server/public.c
index 5dfdfbf92ad9..d3fde6142a2d 100644
--- a/server/public.c
+++ b/server/public.c
@@ -1013,8 +1013,7 @@ free_interns (void)
struct connection *conn = threadlocal_get_conn ();
string_vector *list = conn ? &conn->interns : &global_interns;
- string_vector_iter (list, (void *) free);
- string_vector_reset (list);
+ string_vector_empty (list);
}
static const char *
diff --git a/common/utils/environ.c b/common/utils/environ.c
index ddcf02666ca3..6777d4d48452 100644
--- a/common/utils/environ.c
+++ b/common/utils/environ.c
@@ -111,7 +111,6 @@ copy_environ (char **env, ...)
return ret.ptr;
error:
- string_vector_iter (&ret, (void *) free);
- free (ret.ptr);
+ string_vector_empty (&ret);
return NULL;
}
diff --git a/plugins/iso/iso.c b/plugins/iso/iso.c
index e8c915a4677e..14d4bd504801 100644
--- a/plugins/iso/iso.c
+++ b/plugins/iso/iso.c
@@ -128,8 +128,7 @@ make_iso (void)
static void
iso_unload (void)
{
- string_vector_iter (&dirs, (void *) free);
- free (dirs.ptr);
+ string_vector_empty (&dirs);
if (fd >= 0)
close (fd);
diff --git a/plugins/split/split.c b/plugins/split/split.c
index 3d909cdf6b12..2d12df66782e 100644
--- a/plugins/split/split.c
+++ b/plugins/split/split.c
@@ -64,8 +64,7 @@ static pthread_mutex_t lseek_lock = PTHREAD_MUTEX_INITIALIZER;
static void
split_unload (void)
{
- string_vector_iter (&filenames, (void *) free);
- free (filenames.ptr);
+ string_vector_empty (&filenames);
}
static int