Merge pull request #7454 from neosilky/cocci-fixes

Apply more fixes from Coccinelle
This commit is contained in:
Lennart Poettering 2017-11-24 13:29:32 +01:00 committed by GitHub
commit e92b78b561
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 41 additions and 96 deletions

View file

@ -127,9 +127,7 @@ khash* khash_unref(khash *h) {
safe_close(h->fd);
free(h->algorithm);
free(h);
return NULL;
return mfree(h);
}
int khash_dup(khash *h, khash **ret) {

View file

@ -359,7 +359,7 @@ static int write_to_console(
highlight = LOG_PRI(level) <= LOG_ERR && show_color;
if (show_location) {
snprintf(location, sizeof(location), "(%s:%i) ", file, line);
xsprintf(location, "(%s:%i) ", file, line);
iovec[n++] = IOVEC_MAKE_STRING(location);
}
@ -798,7 +798,7 @@ static void log_assert(
return;
DISABLE_WARNING_FORMAT_NONLITERAL;
snprintf(buffer, sizeof buffer, format, text, file, line, func);
xsprintf(buffer, format, text, file, line, func);
REENABLE_WARNING;
log_abort_msg = buffer;

View file

@ -777,7 +777,7 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
/* The description might be longer than the buffer, but that's OK, we'll just truncate it here */
DISABLE_WARNING_FORMAT_NONLITERAL;
snprintf(buf, sizeof(buf), format, unit_description(u));
xsprintf(buf, format, unit_description(u));
REENABLE_WARNING;
switch (t) {

View file

@ -346,8 +346,7 @@ static char* merge_unit_ids(const char* unit_log_field, char **pairs) {
STRV_FOREACH_PAIR(unit_id, job_type, pairs) {
next = strlen(unit_log_field) + strlen(*unit_id);
if (!GREEDY_REALLOC(ans, alloc, size + next + 1)) {
free(ans);
return NULL;
return mfree(ans);
}
sprintf(ans + size, "%s%s", unit_log_field, *unit_id);

View file

@ -1680,7 +1680,7 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
format = unit_get_status_message_format(u, t);
DISABLE_WARNING_FORMAT_NONLITERAL;
snprintf(buf, sizeof buf, format, unit_description(u));
xsprintf(buf, format, unit_description(u));
REENABLE_WARNING;
mid = t == JOB_START ? "MESSAGE_ID=" SD_MESSAGE_UNIT_STARTING_STR :

View file

@ -1215,7 +1215,7 @@ static int gather_pid_metadata(
if (get_process_environ(pid, &t) >= 0)
set_iovec_field_free(iovec, n_iovec, "COREDUMP_ENVIRON=", t);
t = strjoin("COREDUMP_TIMESTAMP=", context[CONTEXT_TIMESTAMP], "000000", NULL);
t = strjoin("COREDUMP_TIMESTAMP=", context[CONTEXT_TIMESTAMP], "000000");
if (t)
iovec[(*n_iovec)++] = IOVEC_MAKE_STRING(t);

View file

@ -337,9 +337,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
d->create = arg_whitelist = true;
free(d->name);
d->name = uuid_value;
uuid_value = NULL;
free_and_replace(d->name, uuid_value);
} else
log_warning("Failed to parse luks name switch %s. Ignoring.", value);
}

View file

@ -207,9 +207,7 @@ static int raw_import_maybe_convert_qcow2(RawImport *i) {
}
(void) unlink(i->temp_path);
free(i->temp_path);
i->temp_path = t;
t = NULL;
free_and_replace(i->temp_path, t);
safe_close(i->output_fd);
i->output_fd = converted_fd;

View file

@ -192,7 +192,7 @@ int pull_make_path(const char *url, const char *etag, const char *image_root, co
}
path = strjoin(image_root, "/", strempty(prefix), escaped_url, escaped_etag ? "." : "",
strempty(escaped_etag), strempty(suffix), NULL);
strempty(escaped_etag), strempty(suffix));
if (!path)
return -ENOMEM;
@ -210,7 +210,7 @@ int pull_make_path(const char *url, const char *etag, const char *image_root, co
return r;
path = strjoin(image_root, "/", strempty(prefix), hash, escaped_etag ? "." : "",
strempty(escaped_etag), strempty(suffix), NULL);
strempty(escaped_etag), strempty(suffix));
if (!path)
return -ENOMEM;
}

View file

@ -269,9 +269,7 @@ static int raw_pull_maybe_convert_qcow2(RawPull *i) {
}
(void) unlink(i->temp_path);
free(i->temp_path);
i->temp_path = t;
t = NULL;
free_and_replace(i->temp_path, t);
safe_close(i->raw_job->disk_fd);
i->raw_job->disk_fd = converted_fd;

View file

@ -191,9 +191,7 @@ static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overlo
if (!ascii_is_valid(string))
return -EINVAL;
free(*error_message);
*error_message = string;
string = NULL;
free_and_replace(*error_message, string);
}
break;

View file

@ -393,9 +393,7 @@ static int lease_parse_domain(const uint8_t *option, size_t len, char **ret) {
if (dns_name_is_root(normalized))
return -EINVAL;
free(*ret);
*ret = normalized;
normalized = NULL;
free_and_replace(*ret, normalized);
return 0;
}
@ -684,9 +682,7 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void
return 0;
}
free(lease->timezone);
lease->timezone = tz;
tz = NULL;
free_and_replace(lease->timezone, tz);
break;
}

View file

@ -1476,8 +1476,7 @@ static struct node *bus_node_allocate(sd_bus *bus, const char *path) {
r = hashmap_put(bus->nodes, n->path, n);
if (r < 0) {
free(n->path);
free(n);
return NULL;
return mfree(n);
}
if (parent)

View file

@ -786,9 +786,7 @@ static int parse_container_unix_address(sd_bus *b, const char **p, char **guid)
if (!machine_name_is_valid(machine))
return -EINVAL;
free(b->machine);
b->machine = machine;
machine = NULL;
free_and_replace(b->machine, machine);
} else {
b->machine = mfree(b->machine);
}

View file

@ -678,13 +678,9 @@ static int device_update_properties_bufs(sd_device *device) {
i++;
}
free(device->properties_nulstr);
device->properties_nulstr = buf_nulstr;
buf_nulstr = NULL;
free_and_replace(device->properties_nulstr, buf_nulstr);
device->properties_nulstr_len = nulstr_len;
free(device->properties_strv);
device->properties_strv = buf_strv;
buf_strv = NULL;
free_and_replace(device->properties_strv, buf_strv);
device->properties_buf_outdated = false;

View file

@ -215,9 +215,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
if (r < 0)
return r;
free(device->syspath);
device->syspath = syspath;
syspath = NULL;
free_and_replace(device->syspath, syspath);
device->devpath = devpath;
@ -347,9 +345,7 @@ int device_set_devtype(sd_device *device, const char *_devtype) {
if (r < 0)
return r;
free(device->devtype);
device->devtype = devtype;
devtype = NULL;
free_and_replace(device->devtype, devtype);
return 0;
}
@ -394,9 +390,7 @@ int device_set_devname(sd_device *device, const char *_devname) {
if (r < 0)
return r;
free(device->devname);
device->devname = devname;
devname = NULL;
free_and_replace(device->devname, devname);
return 0;
}
@ -761,9 +755,7 @@ int device_set_subsystem(sd_device *device, const char *_subsystem) {
if (r < 0)
return r;
free(device->subsystem);
device->subsystem = subsystem;
subsystem = NULL;
free_and_replace(device->subsystem, subsystem);
device->subsystem_set = true;
@ -786,9 +778,7 @@ static int device_set_drivers_subsystem(sd_device *device, const char *_subsyste
if (r < 0)
return r;
free(device->driver_subsystem);
device->driver_subsystem = subsystem;
subsystem = NULL;
free_and_replace(device->driver_subsystem, subsystem);
return 0;
}
@ -936,9 +926,7 @@ int device_set_driver(sd_device *device, const char *_driver) {
if (r < 0)
return r;
free(device->driver);
device->driver = driver;
driver = NULL;
free_and_replace(device->driver, driver);
device->driver_set = true;
@ -1045,9 +1033,7 @@ static int device_set_sysname(sd_device *device) {
if (len == 0)
sysnum = NULL;
free(device->sysname);
device->sysname = sysname;
sysname = NULL;
free_and_replace(device->sysname, sysname);
device->sysnum = sysnum;

View file

@ -113,8 +113,7 @@ _public_ struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb) {
return NULL;
sd_hwdb_unref(hwdb->hwdb);
udev_list_cleanup(&hwdb->properties_list);
free(hwdb);
return NULL;
return mfree(hwdb);
}
/**

View file

@ -493,8 +493,7 @@ _public_ struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monit
close(udev_monitor->sock);
udev_list_cleanup(&udev_monitor->filter_subsystem_list);
udev_list_cleanup(&udev_monitor->filter_tag_list);
free(udev_monitor);
return NULL;
return mfree(udev_monitor);
}
/**

View file

@ -115,8 +115,7 @@ _public_ struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue)
safe_close(udev_queue->fd);
free(udev_queue);
return NULL;
return mfree(udev_queue);
}
/**

View file

@ -136,8 +136,7 @@ _public_ struct udev *udev_unref(struct udev *udev) {
udev->refcount--;
if (udev->refcount > 0)
return udev;
free(udev);
return NULL;
return mfree(udev);
}
/**

View file

@ -201,9 +201,7 @@ static int x11_read_data(Context *c) {
p = &c->x11_options;
if (p) {
free(*p);
*p = a[2];
a[2] = NULL;
free_and_replace(*p, a[2]);
}
}

View file

@ -403,9 +403,7 @@ int config_parse_network_zone(
return 0;
}
free(settings->network_zone);
settings->network_zone = j;
j = NULL;
free_and_replace(settings->network_zone, j);
return 0;
}

View file

@ -78,8 +78,7 @@ Condition* condition_new(ConditionType type, const char *parameter, bool trigger
r = free_and_strdup(&c->parameter, parameter);
if (r < 0) {
free(c);
return NULL;
return mfree(c);
}
return c;

View file

@ -648,8 +648,7 @@ DissectedImage* dissected_image_unref(DissectedImage *m) {
strv_free(m->machine_info);
strv_free(m->os_release);
free(m);
return NULL;
return mfree(m);
}
static int is_loop_device(const char *path) {

View file

@ -152,9 +152,7 @@ LoopDevice* loop_device_unref(LoopDevice *d) {
}
free(d->node);
free(d);
return NULL;
return mfree(d);
}
void loop_device_relinquish(LoopDevice *d) {

View file

@ -649,13 +649,8 @@ int image_rename(Image *i, const char *new_name) {
if (file_attr & FS_IMMUTABLE_FL)
(void) chattr_path(new_path, FS_IMMUTABLE_FL, FS_IMMUTABLE_FL);
free(i->path);
i->path = new_path;
new_path = NULL;
free(i->name);
i->name = nn;
nn = NULL;
free_and_replace(i->path, new_path);
free_and_replace(i->name, nn);
STRV_FOREACH(j, settings) {
r = rename_auxiliary_file(*j, new_name, ".nspawn");

View file

@ -75,9 +75,7 @@ static int context_read_data(Context *c) {
else if (r < 0)
log_warning_errno(r, "Failed to get target of /etc/localtime: %m");
free(c->zone);
c->zone = t;
t = NULL;
free_and_replace(c->zone, t);
c->local_rtc = clock_is_localtime(NULL) > 0;

View file

@ -94,7 +94,7 @@ static int prepare(char *dir, char *filename)
if (r < 0 && errno != EEXIST)
return -errno;
snprintf(buf, sizeof buf, "%s/%s", dir, filename);
xsprintf(buf, "%s/%s", dir, filename);
fd = open(buf, O_RDWR|O_CREAT|O_CLOEXEC, S_IRUSR|S_IWUSR);
if (fd < 0)

View file

@ -275,7 +275,7 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
goto out;
}
snprintf(slots, sizeof slots, "%s/slots", udev_device_get_syspath(pci));
xsprintf(slots, "%s/slots", udev_device_get_syspath(pci));
dir = opendir(slots);
if (!dir) {
err = -errno;
@ -294,7 +294,7 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
if (i < 1)
continue;
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
xsprintf(str, "%s/%s/address", slots, dent->d_name);
if (read_one_line_file(str, &address) >= 0) {
/* match slot address with device by stripping the function */
if (strneq(address, udev_device_get_sysname(names->pcidev), strlen(address)))