]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/iovec-wrapper: drop unused code
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 14 Apr 2026 06:28:28 +0000 (08:28 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 16 Apr 2026 15:21:56 +0000 (17:21 +0200)
All non-test users iovec_wrapper define the struct as a field in a
bigger structure, so we never free it individually. Let's simplify the
code and assume it is never null.

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

index b4519f808d5e9366229f6f0db0774ba85df79ba6..7f91f5e893b8a23bcbed7ca4e0a3bbbac2c13948 100644 (file)
@@ -7,10 +7,6 @@
 #include "iovec-wrapper.h"
 #include "string-util.h"
 
-struct iovec_wrapper *iovw_new(void) {
-        return new0(struct iovec_wrapper, 1);
-}
-
 void iovw_done(struct iovec_wrapper *iovw) {
         assert(iovw);
 
@@ -27,22 +23,6 @@ void iovw_done_free(struct iovec_wrapper *iovw) {
         iovw_done(iovw);
 }
 
-struct iovec_wrapper *iovw_free_free(struct iovec_wrapper *iovw) {
-        if (!iovw)
-                return NULL;
-
-        iovw_done_free(iovw);
-        return mfree(iovw);
-}
-
-struct iovec_wrapper *iovw_free(struct iovec_wrapper *iovw) {
-        if (!iovw)
-                return NULL;
-
-        iovw_done(iovw);
-        return mfree(iovw);
-}
-
 int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len) {
         assert(iovw);
 
@@ -118,8 +98,7 @@ void iovw_rebase(struct iovec_wrapper *iovw, void *old, void *new) {
 }
 
 size_t iovw_size(const struct iovec_wrapper *iovw) {
-        if (!iovw)
-                return 0;
+        assert(iovw);
 
         return iovec_total_size(iovw->iovec, iovw->count);
 }
index 94b39feb15250b148a584c503dba96ea3d96f84b..bfe739ecf1ed92cc1524db22ee1cce162472d9ea 100644 (file)
@@ -8,12 +8,6 @@ struct iovec_wrapper {
         size_t count;
 };
 
-struct iovec_wrapper *iovw_new(void);
-struct iovec_wrapper *iovw_free(struct iovec_wrapper *iovw);
-struct iovec_wrapper *iovw_free_free(struct iovec_wrapper *iovw);
-
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct iovec_wrapper*, iovw_free_free);
-
 void iovw_done_free(struct iovec_wrapper *iovw);
 void iovw_done(struct iovec_wrapper *iovw);
 
index f77ed205a7086a6f1aefb19ab23dc1328b11ae87..a62f54006e20fccde6a0ef14983135d6cbbd046c 100644 (file)
@@ -261,13 +261,12 @@ static void test_log_context(void) {
                         IOVEC_MAKE_STRING("ABC=def"),
                         IOVEC_MAKE_STRING("GHI=jkl"),
                 };
-                _cleanup_free_ struct iovec_wrapper *iovw = NULL;
-                ASSERT_NOT_NULL(iovw = iovw_new());
-                ASSERT_OK(iovw_consume(iovw, strdup("MNO=pqr"), STRLEN("MNO=pqr") + 1));
+                struct iovec_wrapper iovw = {};
+                ASSERT_OK(iovw_consume(&iovw, strdup("MNO=pqr"), STRLEN("MNO=pqr") + 1));
 
                 LOG_CONTEXT_PUSH_IOV(iov, ELEMENTSOF(iov));
                 LOG_CONTEXT_PUSH_IOV(iov, ELEMENTSOF(iov));
-                LOG_CONTEXT_CONSUME_IOV(iovw->iovec, iovw->count);
+                LOG_CONTEXT_CONSUME_IOV(iovw.iovec, iovw.count);
                 LOG_CONTEXT_PUSH("STU=vwx");
 
                 ASSERT_EQ(log_context_num_contexts(), 3U);