basic/iovec-wrapper: fix potential memleak on error
Also reorder the functions in the call stack order.
This commit is contained in:
+11
-11
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user