basic/iovec-wrapper: fix potential memleak on error

Also reorder the functions in the call stack order.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-04-17 12:19:40 +02:00
parent 5fdc15f408
commit 13b6ba9775
2 changed files with 12 additions and 12 deletions
+11 -11
View File
@@ -41,17 +41,6 @@ int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len) {
return 0;
}
int iovw_append(struct iovec_wrapper *iovw, const void *data, size_t len) {
if (len == 0)
return 0;
void *c = memdup(data, len);
if (!c)
return -ENOMEM;
return iovw_put(iovw, c, len);
}
int iovw_consume(struct iovec_wrapper *iovw, void *data, size_t len) {
/* Move data into iovw or free on error */
int r;
@@ -63,6 +52,17 @@ int iovw_consume(struct iovec_wrapper *iovw, void *data, size_t len) {
return r;
}
int iovw_append(struct iovec_wrapper *iovw, const void *data, size_t len) {
if (len == 0)
return 0;
void *c = memdup(data, len);
if (!c)
return -ENOMEM;
return iovw_consume(iovw, c, len);
}
int iovw_put_string_field_full(struct iovec_wrapper *iovw, bool replace, const char *field, const char *value) {
_cleanup_free_ char *x = NULL;
int r;
+1 -1
View File
@@ -12,8 +12,8 @@ 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);
int iovw_append(struct iovec_wrapper *iovw, const void *data, size_t len);
int iovw_consume(struct iovec_wrapper *iovw, void *data, size_t len);
int iovw_append(struct iovec_wrapper *iovw, const void *data, size_t len);
static inline bool iovw_isempty(const struct iovec_wrapper *iovw) {
return !iovw || iovw->count == 0;