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.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user