summaryrefslogtreecommitdiffstats
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-10-31 16:05:49 +0100
committerLennart Poettering <lennart@poettering.net>2024-10-31 23:08:11 +0100
commit0e3e075b56659882b0bbb362b1bda5d747a64537 (patch)
tree290c89e2727a9d97397fc6abf29050d856a2bddf /src/basic
parentiovw: add simpler iovw_done() destructor (diff)
downloadsystemd-0e3e075b56659882b0bbb362b1bda5d747a64537.tar.xz
systemd-0e3e075b56659882b0bbb362b1bda5d747a64537.zip
iovw: normalize destructors
instead of passing a boolean picking the destruction method just have different functions. That's much nicer in context of _cleanup_, and how we usually do things.
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/iovec-wrapper.c21
-rw-r--r--src/basic/iovec-wrapper.h11
2 files changed, 15 insertions, 17 deletions
diff --git a/src/basic/iovec-wrapper.c b/src/basic/iovec-wrapper.c
index b335acd108..5cc3cc2f93 100644
--- a/src/basic/iovec-wrapper.c
+++ b/src/basic/iovec-wrapper.c
@@ -9,22 +9,27 @@ struct iovec_wrapper *iovw_new(void) {
return new0(struct iovec_wrapper, 1);
}
-void iovw_free_contents(struct iovec_wrapper *iovw, bool free_vectors) {
+void iovw_done(struct iovec_wrapper *iovw) {
assert(iovw);
- if (free_vectors)
- for (size_t i = 0; i < iovw->count; i++)
- free(iovw->iovec[i].iov_base);
-
iovw->iovec = mfree(iovw->iovec);
iovw->count = 0;
}
+void iovw_done_free(struct iovec_wrapper *iovw) {
+ assert(iovw);
+
+ FOREACH_ARRAY(i, iovw->iovec, iovw->count)
+ iovec_done(i);
+
+ iovw_done(iovw);
+}
+
struct iovec_wrapper *iovw_free_free(struct iovec_wrapper *iovw) {
if (!iovw)
return NULL;
- iovw_free_contents(iovw, /* free_vectors= */ true);
+ iovw_done_free(iovw);
return mfree(iovw);
}
@@ -32,7 +37,7 @@ struct iovec_wrapper *iovw_free(struct iovec_wrapper *iovw) {
if (!iovw)
return NULL;
- iovw_free_contents(iovw, /* free_vectors= */ false);
+ iovw_done(iovw);
return mfree(iovw);
}
@@ -124,7 +129,7 @@ int iovw_append(struct iovec_wrapper *target, const struct iovec_wrapper *source
rollback:
for (size_t i = original_count; i < target->count; i++)
- free(target->iovec[i].iov_base);
+ iovec_done(target->iovec + i);
target->count = original_count;
return r;
diff --git a/src/basic/iovec-wrapper.h b/src/basic/iovec-wrapper.h
index 4754b98fbb..4778fa6b27 100644
--- a/src/basic/iovec-wrapper.h
+++ b/src/basic/iovec-wrapper.h
@@ -17,15 +17,8 @@ struct iovec_wrapper *iovw_free_free(struct iovec_wrapper *iovw);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct iovec_wrapper*, iovw_free_free);
-void iovw_free_contents(struct iovec_wrapper *iovw, bool free_vectors);
-
-static inline void iovw_done_free(struct iovec_wrapper *iovw) {
- iovw_free_contents(iovw, true);
-}
-
-static inline void iovw_done(struct iovec_wrapper *iovw) {
- iovw_free_contents(iovw, false);
-}
+void iovw_done_free(struct iovec_wrapper *iovw);
+void iovw_done(struct iovec_wrapper *iovw);
int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len);
static inline int iovw_consume(struct iovec_wrapper *iovw, void *data, size_t len) {