]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
iovw: normalize destructors
authorLennart Poettering <lennart@poettering.net>
Thu, 31 Oct 2024 15:05:49 +0000 (16:05 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 31 Oct 2024 22:08:11 +0000 (23:08 +0100)
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.

src/basic/iovec-wrapper.c
src/basic/iovec-wrapper.h

index b335acd1089d0156d8c7ad63005cd432eb8030d4..5cc3cc2f93d5b9282b3935eece1530ad297294bd 100644 (file)
@@ -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;
index 4754b98fbb80fce83c68140672f262c5da206d65..4778fa6b275739df24864cf44f3fdc939f300351 100644 (file)
@@ -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) {