tree-wide: avoid uninitialized warning on _cleanup_ variables

With some versions of the compiler, the _cleanup_ attr makes it think
the variable might be freed/closed when uninitialized, even though it
cannot happen. The added cost is small enough to be worth the benefit,
and optimized builds will help reduce it even further.
This commit is contained in:
Luca Boccassi
2021-04-14 12:25:06 +01:00
parent be084c0dd1
commit c2b2df604b
61 changed files with 106 additions and 106 deletions
+3 -3
View File
@@ -211,7 +211,7 @@ int acl_search_groups(const char *path, char ***ret_groups) {
int parse_acl(const char *text, acl_t *acl_access, acl_t *acl_default, bool want_mask) {
_cleanup_free_ char **a = NULL, **d = NULL; /* strings are not freed */
_cleanup_strv_free_ char **split;
_cleanup_strv_free_ char **split = NULL;
char **entry;
int r = -EINVAL;
_cleanup_(acl_freep) acl_t a_acl = NULL, d_acl = NULL;
@@ -233,7 +233,7 @@ int parse_acl(const char *text, acl_t *acl_access, acl_t *acl_default, bool want
}
if (!strv_isempty(a)) {
_cleanup_free_ char *join;
_cleanup_free_ char *join = NULL;
join = strv_join(a, ",");
if (!join)
@@ -251,7 +251,7 @@ int parse_acl(const char *text, acl_t *acl_access, acl_t *acl_default, bool want
}
if (!strv_isempty(d)) {
_cleanup_free_ char *join;
_cleanup_free_ char *join = NULL;
join = strv_join(d, ",");
if (!join)
+1 -1
View File
@@ -184,7 +184,7 @@ static void log_job_error_with_service_result(const char* service, const char *r
service_shell_quoted = shell_maybe_quote(service, ESCAPE_BACKSLASH);
if (!strv_isempty((char**) extra_args)) {
_cleanup_free_ char *t;
_cleanup_free_ char *t = NULL;
t = strv_join((char**) extra_args, " ");
systemctl = strjoina("systemctl ", t ? : "<args>");
+1 -1
View File
@@ -240,7 +240,7 @@ static int clean_posix_shm_internal(const char *dirname, DIR *dir, uid_t uid, gi
}
if (S_ISDIR(st.st_mode)) {
_cleanup_closedir_ DIR *kid;
_cleanup_closedir_ DIR *kid = NULL;
kid = xopendirat(dirfd(dir), de->d_name, O_NOFOLLOW|O_NOATIME);
if (!kid) {
+1 -1
View File
@@ -55,7 +55,7 @@ int clock_set_hwclock(const struct tm *tm) {
}
int clock_is_localtime(const char* adjtime_path) {
_cleanup_fclose_ FILE *f;
_cleanup_fclose_ FILE *f = NULL;
int r;
if (!adjtime_path)
+15 -15
View File
@@ -1409,7 +1409,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
case TABLE_TIMESTAMP:
case TABLE_TIMESTAMP_UTC:
case TABLE_TIMESTAMP_RELATIVE: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
char *ret;
p = new(char, FORMAT_TIMESTAMP_MAX);
@@ -1431,7 +1431,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
case TABLE_TIMESPAN:
case TABLE_TIMESPAN_MSEC: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, FORMAT_TIMESPAN_MAX);
if (!p)
@@ -1446,7 +1446,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_SIZE: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, FORMAT_BYTES_MAX);
if (!p)
@@ -1460,7 +1460,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_BPS: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
size_t n;
p = new(char, FORMAT_BYTES_MAX+2);
@@ -1478,7 +1478,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_INT: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, DECIMAL_STR_WIDTH(d->int_val) + 1);
if (!p)
@@ -1490,7 +1490,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_INT8: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, DECIMAL_STR_WIDTH(d->int8) + 1);
if (!p)
@@ -1502,7 +1502,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_INT16: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, DECIMAL_STR_WIDTH(d->int16) + 1);
if (!p)
@@ -1514,7 +1514,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_INT32: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, DECIMAL_STR_WIDTH(d->int32) + 1);
if (!p)
@@ -1526,7 +1526,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_INT64: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, DECIMAL_STR_WIDTH(d->int64) + 1);
if (!p)
@@ -1538,7 +1538,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_UINT: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, DECIMAL_STR_WIDTH(d->uint_val) + 1);
if (!p)
@@ -1550,7 +1550,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_UINT8: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, DECIMAL_STR_WIDTH(d->uint8) + 1);
if (!p)
@@ -1562,7 +1562,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_UINT16: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, DECIMAL_STR_WIDTH(d->uint16) + 1);
if (!p)
@@ -1574,7 +1574,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_UINT32: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, DECIMAL_STR_WIDTH(d->uint32) + 1);
if (!p)
@@ -1586,7 +1586,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_UINT64: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, DECIMAL_STR_WIDTH(d->uint64) + 1);
if (!p)
@@ -1598,7 +1598,7 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
}
case TABLE_PERCENT: {
_cleanup_free_ char *p;
_cleanup_free_ char *p = NULL;
p = new(char, DECIMAL_STR_WIDTH(d->percent) + 2);
if (!p)
+1 -1
View File
@@ -2950,7 +2950,7 @@ static int read_presets(UnitFileScope scope, const char *root_dir, UnitFilePrese
return r;
STRV_FOREACH(p, files) {
_cleanup_fclose_ FILE *f;
_cleanup_fclose_ FILE *f = NULL;
int n = 0;
f = fopen(*p, "re");
+2 -2
View File
@@ -294,7 +294,7 @@ static bool print_multiline(
continuation * prefix, "",
color_on, len, pos, color_off);
else {
_cleanup_free_ char *e;
_cleanup_free_ char *e = NULL;
e = ellipsize_mem(pos, len, n_columns - prefix,
tail_line ? 100 : 90);
@@ -1651,7 +1651,7 @@ int show_journal_by_unit(
return r;
if (DEBUG_LOGGING) {
_cleanup_free_ char *filter;
_cleanup_free_ char *filter = NULL;
filter = journal_make_match_string(j);
if (!filter)
+1 -1
View File
@@ -147,7 +147,7 @@ bool net_match_config(
const char *ssid,
const struct ether_addr *bssid) {
_cleanup_free_ char *iftype_str;
_cleanup_free_ char *iftype_str = NULL;
const char *path = NULL;
assert(match);
+1 -1
View File
@@ -34,7 +34,7 @@
#include "time-util.h"
int parse_sleep_config(SleepConfig **ret_sleep_config) {
_cleanup_(free_sleep_configp) SleepConfig *sc;
_cleanup_(free_sleep_configp) SleepConfig *sc = NULL;
int allow_suspend = -1, allow_hibernate = -1,
allow_s2h = -1, allow_hybrid_sleep = -1;