sza *= 2;
- free(bufa);
- bufa = NULL;
+ bufa = mfree(bufa);
}
p = bufa;
if (m < 0) {
if (errno == ERANGE) {
szb *= 2;
- free(bufb);
- bufb = NULL;
+ bufb = mfree(bufb);
continue;
}
#define malloc0(n) (calloc((n), 1))
+static inline void *mfree(void *memory) {
+ free(memory);
+ return NULL;
+}
+
static inline const char* yes_no(bool b) {
return b ? "yes" : "no";
}
case POLICY_ITEM_SEND:
case POLICY_ITEM_RECV:
- if (streq(name, "*")) {
- free(name);
- name = NULL;
- }
+ if (streq(name, "*"))
+ name = mfree(name);
break;
r = open_follow(&filename, &f, symlink_names, &id);
if (r < 0) {
- free(filename);
- filename = NULL;
-
+ filename = mfree(filename);
if (r != -ENOENT)
return r;
}
r = open_follow(&filename, &f, symlink_names, &id);
if (r < 0) {
- free(filename);
- filename = NULL;
-
+ filename = mfree(filename);
if (r != -ENOENT)
return r;
arg_default_rlimit[j] = NULL;
}
- free(arg_default_unit);
- arg_default_unit = NULL;
+ arg_default_unit = mfree(arg_default_unit);
free_join_controllers();
- strv_free(arg_default_environment);
- arg_default_environment = NULL;
+ arg_default_environment = strv_free(arg_default_environment);
set_free(arg_syscall_archs);
arg_syscall_archs = NULL;
break;
}
- free(n);
- n = NULL;
+ n = mfree(n);
}
}
/* If the description string is simply the
* volume name, then let's not show this
* twice */
- free(description);
- description = NULL;
+ description = mfree(description);
}
if (mount_point && description)
path_kill_slashes(arg_root);
- if (path_equal(arg_root, "/")) {
- free(arg_root);
- arg_root = NULL;
- }
+ if (path_equal(arg_root, "/"))
+ arg_root = mfree(arg_root);
break;
i->current_ancestry++;
- free(path);
- path = NULL;
+ path = mfree(path);
}
log_info("Pulling layer %s...", layer);
i->current_ancestry++;
- free(path);
- path = NULL;
+ path = mfree(path);
}
log_info("Pulling layer %s...", layer);
if (r < 0)
return r;
- free(lang);
- lang = NULL;
+ lang = mfree(lang);
}
if (with_language) {
if (filename && access(filename, R_OK) < 0) {
log_full(errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
"File %s is not readable: %m", filename);
- free(filename);
- filename = NULL;
+ filename = mfree(filename);
}
if (filename && !endswith(filename, ".xz") && !endswith(filename, ".lz4")) {
}
}
- strv_free(patterns);
- patterns = NULL;
+ patterns = strv_free(patterns);
STRV_FOREACH(i, arg_user_units) {
_cleanup_free_ char *u = NULL;
if (r < 0)
goto fail;
- free(value);
- value = NULL;
+ value = mfree(value);
} else
u = 0;
}
}
- free(argument_type);
- free(argument_direction);
- argument_type = argument_direction = NULL;
+ argument_type = mfree(argument_type);
+ argument_direction = mfree(argument_direction);
}
state = STATE_METHOD;
if (!strextend(&context->member_signature, argument_type, NULL))
return log_oom();
- free(argument_type);
- argument_type = NULL;
+ argument_type = mfree(argument_type);
}
state = STATE_SIGNAL;
printf("Local Addresses:\n");
print_local_addresses(a, (unsigned) n);
- free(a);
+ a = mfree(a);
- a = NULL;
n = local_gateways(NULL, 0, AF_UNSPEC, &a);
assert_se(n >= 0);
log_warning("Existing logind session ID %s used by new audit session, ignoring", id);
audit_id = 0;
- free(id);
- id = NULL;
+ id = mfree(id);
}
}
if (!id) {
do {
- free(id);
- id = NULL;
+ id = mfree(id);
if (asprintf(&id, "c%lu", ++m->session_counter) < 0)
return -ENOMEM;
return r;
do {
- free(id);
- id = NULL;
+ id = mfree(id);
if (asprintf(&id, "%lu", ++m->inhibit_counter) < 0)
return -ENOMEM;
strv_free(m->lower);
}
- free(arg_custom_mounts);
- arg_custom_mounts = NULL;
+ arg_custom_mounts = mfree(arg_custom_mounts);
arg_n_custom_mounts = 0;
}
case 'M':
if (isempty(optarg)) {
- free(arg_machine);
- arg_machine = NULL;
+ arg_machine = mfree(arg_machine);
} else {
if (!machine_name_is_valid(optarg)) {
log_error("Invalid machine name: %s", optarg);
}
}
- free(addresses);
- addresses = NULL;
+ addresses = mfree(addresses);
n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses);
if (n_addresses > 0) {
return -ENOMEM;
}
- free(continuation);
- continuation = NULL;
+ continuation = mfree(continuation);
p = c;
} else
p = l;
if (! dir || last) {
printf(dir ? " " : " Drop-In: ");
- free(dir);
- dir = NULL;
+ dir = mfree(dir);
if (path_get_parent(*dropin, &dir) < 0) {
log_oom();
goto finish;
}
- free(group_tmp);
- group_tmp = NULL;
+ group_tmp = mfree(group_tmp);
}
if (gshadow) {
if (rename(gshadow_tmp, gshadow_path) < 0) {
goto finish;
}
- free(gshadow_tmp);
- gshadow_tmp = NULL;
+ gshadow_tmp = mfree(gshadow_tmp);
}
}
goto finish;
}
- free(passwd_tmp);
- passwd_tmp = NULL;
+ passwd_tmp = mfree(passwd_tmp);
}
if (shadow) {
if (rename(shadow_tmp, shadow_path) < 0) {
goto finish;
}
- free(shadow_tmp);
- shadow_tmp = NULL;
+ shadow_tmp = mfree(shadow_tmp);
}
r = 0;
}
/* Verify name */
- if (isempty(name) || streq(name, "-")) {
- free(name);
- name = NULL;
- }
+ if (isempty(name) || streq(name, "-"))
+ name = mfree(name);
if (name) {
r = specifier_printf(name, specifier_table, NULL, &resolved_name);
}
/* Verify id */
- if (isempty(id) || streq(id, "-")) {
- free(id);
- id = NULL;
- }
+ if (isempty(id) || streq(id, "-"))
+ id = mfree(id);
if (id) {
r = specifier_printf(id, specifier_table, NULL, &resolved_id);
}
/* Verify description */
- if (isempty(description) || streq(description, "-")) {
- free(description);
- description = NULL;
- }
+ if (isempty(description) || streq(description, "-"))
+ description = mfree(description);
if (description) {
if (!valid_gecos(description)) {
}
/* Verify home */
- if (isempty(home) || streq(home, "-")) {
- free(home);
- home = NULL;
- }
+ if (isempty(home) || streq(home, "-"))
+ home = mfree(home);
if (home) {
if (!valid_home(home)) {
assert_se(cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00", 0, &unescaped) < 0);
assert_se(cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "abc\\\"\b\f\a\n\r\t\v\003\177\234\313\\000\\x00"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
/* incomplete sequences */
assert_se(cunescape("\\x0", 0, &unescaped) < 0);
assert_se(cunescape("\\x0", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "\\x0"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\x", 0, &unescaped) < 0);
assert_se(cunescape("\\x", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "\\x"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\", 0, &unescaped) < 0);
assert_se(cunescape("\\", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "\\"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\11", 0, &unescaped) < 0);
assert_se(cunescape("\\11", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "\\11"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\1", 0, &unescaped) < 0);
assert_se(cunescape("\\1", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "\\1"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\u0000", 0, &unescaped) < 0);
assert_se(cunescape("\\u00DF\\U000000df\\u03a0\\U00000041", UNESCAPE_RELAX, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, "ßßΠA"));
- free(unescaped);
- unescaped = NULL;
+ unescaped = mfree(unescaped);
assert_se(cunescape("\\073", 0, &unescaped) >= 0);
assert_se(streq_ptr(unescaped, ";"));
write_string_file(path, "foo", WRITE_STRING_FILE_CREATE);
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(streq(hostname, "foo"));
- free(hostname);
- hostname = NULL;
+ hostname = mfree(hostname);
/* with comment */
write_string_file(path, "# comment\nfoo", WRITE_STRING_FILE_CREATE);
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(hostname);
assert_se(streq(hostname, "foo"));
- free(hostname);
- hostname = NULL;
+ hostname = mfree(hostname);
/* with comment and extra whitespace */
write_string_file(path, "# comment\n\n foo ", WRITE_STRING_FILE_CREATE);
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(hostname);
assert_se(streq(hostname, "foo"));
- free(hostname);
- hostname = NULL;
+ hostname = mfree(hostname);
/* cleans up name */
write_string_file(path, "!foo/bar.com", WRITE_STRING_FILE_CREATE);
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(hostname);
assert_se(streq(hostname, "foobar.com"));
- free(hostname);
- hostname = NULL;
+ hostname = mfree(hostname);
/* no value set */
hostname = (char*) 0x1234;
/* Hmm, first try with cached
* passwords failed, so let's retry
* with a normal password request */
- free(packet);
- packet = NULL;
+ packet = mfree(packet);
if (asprintf(&packet, "*\002%c%s%n", (int) (strlen(message) + 1), message, &n) < 0)
return -ENOMEM;
* might produce conflicting IDs if the parent does not provide a
* unique and predictable name.
*/
- if (!supported_parent) {
- free(path);
- path = NULL;
- }
+ if (!supported_parent)
+ path = mfree(path);
/*
* Do not return block devices without a well-known transport. Some
* devices do not expose their buses and do not provide a unique
* and predictable name that way.
*/
- if (streq(udev_device_get_subsystem(dev), "block") && !supported_transport) {
- free(path);
- path = NULL;
- }
+ if (streq(udev_device_get_subsystem(dev), "block") && !supported_transport)
+ path = mfree(path);
out:
if (path != NULL) {
uid = 0;
gid = 0;
mode = 0;
- strv_free(tags);
- tags = NULL;
+ tags = strv_free(tags);
break;
case TK_A_OWNER_ID:
uid = cur->key.uid;