Skip to content

Commit

Permalink
convert string_vector_(iter(free) + reset()) to string_vector_empty()
Browse files Browse the repository at this point in the history
(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]>
  • Loading branch information
lersek committed Mar 4, 2023
1 parent 40231e7 commit e36cfb6
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 16 deletions.
3 changes: 1 addition & 2 deletions common/utils/environ.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 1 addition & 8 deletions common/utils/string-vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
3 changes: 1 addition & 2 deletions plugins/iso/iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions plugins/split/split.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions server/public.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down

0 comments on commit e36cfb6

Please sign in to comment.