Merge pull request #34674 from yuwata/reallocarray
tree-wide: replace reallocarray() with GREEDY_REALLOC()
This commit is contained in:
+5
-14
@@ -2377,7 +2377,6 @@ int bus_exec_context_set_transient_property(
|
||||
|
||||
for (;;) {
|
||||
_cleanup_free_ void *copy = NULL;
|
||||
struct iovec *t;
|
||||
const char *eq;
|
||||
const void *p;
|
||||
size_t sz;
|
||||
@@ -2404,28 +2403,20 @@ int bus_exec_context_set_transient_property(
|
||||
if (!journal_field_valid(p, eq - (const char*) p, false))
|
||||
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec));
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
c->log_extra_fields = t;
|
||||
}
|
||||
|
||||
copy = malloc(sz + 1);
|
||||
copy = memdup_suffix0(p, sz);
|
||||
if (!copy)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(copy, p, sz);
|
||||
((uint8_t*) copy)[sz] = 0;
|
||||
|
||||
if (!utf8_is_valid(copy))
|
||||
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8");
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
|
||||
return -ENOMEM;
|
||||
|
||||
c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz);
|
||||
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy);
|
||||
|
||||
copy = NULL;
|
||||
TAKE_PTR(copy);
|
||||
}
|
||||
|
||||
n++;
|
||||
|
||||
@@ -2935,7 +2935,6 @@ int config_parse_log_extra_fields(
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *word = NULL, *k = NULL;
|
||||
struct iovec *t;
|
||||
const char *eq;
|
||||
|
||||
r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
|
||||
@@ -2965,14 +2964,11 @@ int config_parse_log_extra_fields(
|
||||
continue;
|
||||
}
|
||||
|
||||
t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec));
|
||||
if (!t)
|
||||
if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
|
||||
return log_oom();
|
||||
|
||||
c->log_extra_fields = t;
|
||||
c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE_STRING(k);
|
||||
|
||||
k = NULL;
|
||||
TAKE_PTR(k);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-12
@@ -2837,7 +2837,6 @@ MountImage* mount_image_free_many(MountImage *m, size_t *n) {
|
||||
int mount_image_add(MountImage **m, size_t *n, const MountImage *item) {
|
||||
_cleanup_free_ char *s = NULL, *d = NULL;
|
||||
_cleanup_(mount_options_free_allp) MountOptions *options = NULL;
|
||||
MountImage *c;
|
||||
|
||||
assert(m);
|
||||
assert(n);
|
||||
@@ -2870,13 +2869,10 @@ int mount_image_add(MountImage **m, size_t *n, const MountImage *item) {
|
||||
LIST_APPEND(mount_options, options, TAKE_PTR(o));
|
||||
}
|
||||
|
||||
c = reallocarray(*m, *n + 1, sizeof(MountImage));
|
||||
if (!c)
|
||||
if (!GREEDY_REALLOC(*m, *n + 1))
|
||||
return -ENOMEM;
|
||||
|
||||
*m = c;
|
||||
|
||||
c[(*n)++] = (MountImage) {
|
||||
(*m)[(*n)++] = (MountImage) {
|
||||
.source = TAKE_PTR(s),
|
||||
.destination = TAKE_PTR(d),
|
||||
.mount_options = TAKE_PTR(options),
|
||||
@@ -2905,7 +2901,6 @@ int temporary_filesystem_add(
|
||||
const char *options) {
|
||||
|
||||
_cleanup_free_ char *p = NULL, *o = NULL;
|
||||
TemporaryFileSystem *c;
|
||||
|
||||
assert(t);
|
||||
assert(n);
|
||||
@@ -2921,13 +2916,10 @@ int temporary_filesystem_add(
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
c = reallocarray(*t, *n + 1, sizeof(TemporaryFileSystem));
|
||||
if (!c)
|
||||
if (!GREEDY_REALLOC(*t, *n + 1))
|
||||
return -ENOMEM;
|
||||
|
||||
*t = c;
|
||||
|
||||
c[(*n)++] = (TemporaryFileSystem) {
|
||||
(*t)[(*n)++] = (TemporaryFileSystem) {
|
||||
.path = TAKE_PTR(p),
|
||||
.options = TAKE_PTR(o),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user