Skip to content

Commit e36cfb6

Browse files
author
Laszlo Ersek
committed
convert string_vector_(iter(free) + reset()) to string_vector_empty()
(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 <[email protected]> Message-Id: <[email protected]> Acked-by: Richard W.M. Jones <[email protected]> Acked-by: Eric Blake <[email protected]>
1 parent 40231e7 commit e36cfb6

File tree

5 files changed

+5
-16
lines changed

5 files changed

+5
-16
lines changed

Diff for: common/utils/environ.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ copy_environ (char **env, ...)
111111
return ret.ptr;
112112

113113
error:
114-
string_vector_iter (&ret, (void *) free);
115-
free (ret.ptr);
114+
string_vector_empty (&ret);
116115
return NULL;
117116
}

Diff for: common/utils/string-vector.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ DEFINE_POINTER_VECTOR_TYPE (string_vector, char *);
4141

4242
/* This frees both the array and the strings. */
4343
#define CLEANUP_FREE_STRING_VECTOR \
44-
__attribute__ ((cleanup (cleanup_free_string_vector)))
45-
46-
static void __attribute__ ((__unused__))
47-
cleanup_free_string_vector (string_vector *v)
48-
{
49-
string_vector_iter (v, (void*)free);
50-
string_vector_reset (v);
51-
}
44+
__attribute__ ((cleanup (string_vector_empty)))
5245

5346
#endif /* STRING_VECTOR_H */

Diff for: plugins/iso/iso.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ make_iso (void)
128128
static void
129129
iso_unload (void)
130130
{
131-
string_vector_iter (&dirs, (void *) free);
132-
free (dirs.ptr);
131+
string_vector_empty (&dirs);
133132

134133
if (fd >= 0)
135134
close (fd);

Diff for: plugins/split/split.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ static pthread_mutex_t lseek_lock = PTHREAD_MUTEX_INITIALIZER;
6464
static void
6565
split_unload (void)
6666
{
67-
string_vector_iter (&filenames, (void *) free);
68-
free (filenames.ptr);
67+
string_vector_empty (&filenames);
6968
}
7069

7170
static int

Diff for: server/public.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,7 @@ free_interns (void)
10131013
struct connection *conn = threadlocal_get_conn ();
10141014
string_vector *list = conn ? &conn->interns : &global_interns;
10151015

1016-
string_vector_iter (list, (void *) free);
1017-
string_vector_reset (list);
1016+
string_vector_empty (list);
10181017
}
10191018

10201019
static const char *

0 commit comments

Comments
 (0)