diff options
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/iovec-wrapper.c | 21 | ||||
-rw-r--r-- | src/basic/iovec-wrapper.h | 11 |
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) { |