Convert the 11 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.
Signed-off-by: Laszlo Ersek <lersek(a)redhat.com>
---
Notes:
v4:
- split out from the previous [libnbd PATCH v3 05/29] vector: (mostly)
factor out DEFINE_VECTOR_EMPTY
generator/states-connect-socket-activation.c | 9 +++------
lib/handle.c | 12 ++++--------
lib/utils.c | 6 ++----
common/utils/test-vector.c | 3 +--
info/show.c | 3 +--
5 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/generator/states-connect-socket-activation.c
b/generator/states-connect-socket-activation.c
index 7138e7638e30..3b621b8be44f 100644
--- a/generator/states-connect-socket-activation.c
+++ b/generator/states-connect-socket-activation.c
@@ -91,8 +91,7 @@ prepare_socket_activation_environment (string_vector *env)
err:
set_error (errno, "malloc");
- string_vector_iter (env, (void *) free);
- free (env->ptr);
+ string_vector_empty (env);
return -1;
}
@@ -166,8 +165,7 @@ CONNECT_SA.START:
SET_NEXT_STATE (%.DEAD);
set_error (errno, "fork");
close (s);
- string_vector_iter (&env, (void *) free);
- free (env.ptr);
+ string_vector_empty (&env);
return 0;
}
if (pid == 0) { /* child - run command */
@@ -210,8 +208,7 @@ CONNECT_SA.START:
/* Parent. */
close (s);
- string_vector_iter (&env, (void *) free);
- free (env.ptr);
+ string_vector_empty (&env);
h->pid = pid;
h->connaddrlen = sizeof addr;
diff --git a/lib/handle.c b/lib/handle.c
index dfd8c2e5cdb9..fb92f16e6c91 100644
--- a/lib/handle.c
+++ b/lib/handle.c
@@ -128,8 +128,7 @@ nbd_close (struct nbd_handle *h)
/* Free user callbacks first. */
nbd_unlocked_clear_debug_callback (h);
- string_vector_iter (&h->querylist, (void *) free);
- free (h->querylist.ptr);
+ string_vector_empty (&h->querylist);
free (h->bs_entries);
nbd_internal_reset_size_and_flags (h);
for (i = 0; i < h->meta_contexts.len; ++i)
@@ -139,8 +138,7 @@ nbd_close (struct nbd_handle *h)
free_cmd_list (h->cmds_to_issue);
free_cmd_list (h->cmds_in_flight);
free_cmd_list (h->cmds_done);
- string_vector_iter (&h->argv, (void *) free);
- free (h->argv.ptr);
+ string_vector_empty (&h->argv);
if (h->sact_sockpath) {
if (h->pid > 0)
kill (h->pid, SIGTERM);
@@ -164,8 +162,7 @@ nbd_close (struct nbd_handle *h)
free (h->tls_certificates);
free (h->tls_username);
free (h->tls_psk_file);
- string_vector_iter (&h->request_meta_contexts, (void *) free);
- free (h->request_meta_contexts.ptr);
+ string_vector_empty (&h->request_meta_contexts);
free (h->hname);
pthread_mutex_destroy (&h->lock);
free (h);
@@ -379,8 +376,7 @@ nbd_unlocked_get_meta_context (struct nbd_handle *h, size_t i)
int
nbd_unlocked_clear_meta_contexts (struct nbd_handle *h)
{
- string_vector_iter (&h->request_meta_contexts, (void *) free);
- string_vector_reset (&h->request_meta_contexts);
+ string_vector_empty (&h->request_meta_contexts);
return 0;
}
diff --git a/lib/utils.c b/lib/utils.c
index c229ebfc6106..bba4b3846e77 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -93,8 +93,7 @@ nbd_internal_set_argv (struct nbd_handle *h, char **argv)
return -1;
}
- string_vector_iter (&h->argv, (void *) free);
- string_vector_reset (&h->argv);
+ string_vector_empty (&h->argv);
if (nbd_internal_copy_string_list (&h->argv, argv) == -1) {
set_error (errno, "realloc");
@@ -110,8 +109,7 @@ nbd_internal_set_argv (struct nbd_handle *h, char **argv)
int
nbd_internal_set_querylist (struct nbd_handle *h, char **queries)
{
- string_vector_iter (&h->querylist, (void *) free);
- string_vector_reset (&h->querylist);
+ string_vector_empty (&h->querylist);
if (queries) {
if (nbd_internal_copy_string_list (&h->querylist, queries) == -1) {
diff --git a/common/utils/test-vector.c b/common/utils/test-vector.c
index 27c8da1c06ab..8143669e95b9 100644
--- a/common/utils/test-vector.c
+++ b/common/utils/test-vector.c
@@ -151,8 +151,7 @@ test_string_vector (void)
printf ("%s\n", v.ptr[i]);
assert (i == 10);
- string_vector_iter (&v, (void*)free);
- string_vector_reset (&v);
+ string_vector_empty (&v);
}
static void
diff --git a/info/show.c b/info/show.c
index 4bf596715cf9..e6c9b9bf1243 100644
--- a/info/show.c
+++ b/info/show.c
@@ -275,8 +275,7 @@ show_one_export (struct nbd_handle *nbd, const char *desc,
fprintf (fp, "\t},\n");
}
- string_vector_iter (&contexts, (void *) free);
- free (contexts.ptr);
+ string_vector_empty (&contexts);
free (content);
free (export_name);
free (export_desc);