X Tutup
Skip to content

Commit b3f9c17

Browse files
committed
tree-wide: use free_and_strdup_warn()
1 parent 7fb1d98 commit b3f9c17

File tree

12 files changed

+37
-62
lines changed

12 files changed

+37
-62
lines changed

src/core/load-fragment.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,7 @@ int config_parse_socket_bindtodevice(
920920
return 0;
921921
}
922922

923-
if (free_and_strdup(&s->bind_to_device, rvalue) < 0)
924-
return log_oom();
925-
926-
return 0;
923+
return free_and_strdup_warn(&s->bind_to_device, rvalue);
927924
}
928925

929926
int config_parse_exec_input(

src/cryptsetup/cryptsetup-generator.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
667667

668668
r = sscanf(value, "%m[0-9a-fA-F-]=%ms", &uuid, &uuid_value);
669669
if (r != 2)
670-
return free_and_strdup(&arg_default_options, value) < 0 ? log_oom() : 0;
670+
return free_and_strdup_warn(&arg_default_options, value);
671671

672672
if (warn_uuid_invalid(uuid, key))
673673
return 0;
@@ -691,11 +691,8 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
691691
return 0;
692692

693693
n = strspn(value, ALPHANUMERICAL "-");
694-
if (value[n] != '=') {
695-
if (free_and_strdup(&arg_default_keyfile, value) < 0)
696-
return log_oom();
697-
return 0;
698-
}
694+
if (value[n] != '=')
695+
return free_and_strdup_warn(&arg_default_keyfile, value);
699696

700697
uuid = strndup(value, n);
701698
if (!uuid)

src/debug-generator/debug-generator.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,21 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
6868
else if (r > 0)
6969
t = skip_dev_prefix(DEBUGTTY);
7070

71-
if (free_and_strdup(&arg_debug_shell, t) < 0)
72-
return log_oom();
71+
return free_and_strdup_warn(&arg_debug_shell, t);
7372

7473
} else if (streq(key, "systemd.unit")) {
7574

7675
if (proc_cmdline_value_missing(key, value))
7776
return 0;
7877

79-
r = free_and_strdup(&arg_default_unit, value);
80-
if (r < 0)
81-
return log_error_errno(r, "Failed to set default unit %s: %m", value);
78+
return free_and_strdup_warn(&arg_default_unit, value);
8279

8380
} else if (!value) {
8481
const char *target;
8582

8683
target = runlevel_to_target(key);
87-
if (target) {
88-
r = free_and_strdup(&arg_default_unit, target);
89-
if (r < 0)
90-
return log_error_errno(r, "Failed to set default unit %s: %m", target);
91-
}
84+
if (target)
85+
return free_and_strdup_warn(&arg_default_unit, target);
9286
}
9387

9488
return 0;

src/firstboot/firstboot.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,7 @@ static int prompt_loop(const char *text, char **l, unsigned percentage, bool (*i
210210
}
211211

212212
log_info("Selected '%s'.", l[u-1]);
213-
if (free_and_strdup(ret, l[u-1]) < 0)
214-
return log_oom();
215-
216-
return 0;
213+
return free_and_strdup_warn(ret, l[u-1]);
217214
}
218215

219216
if (!is_valid(p)) {

src/fstab-generator/fstab-generator.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -827,16 +827,14 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
827827
if (proc_cmdline_value_missing(key, value))
828828
return 0;
829829

830-
if (free_and_strdup(&arg_root_what, value) < 0)
831-
return log_oom();
830+
return free_and_strdup_warn(&arg_root_what, value);
832831

833832
} else if (streq(key, "rootfstype")) {
834833

835834
if (proc_cmdline_value_missing(key, value))
836835
return 0;
837836

838-
if (free_and_strdup(&arg_root_fstype, value) < 0)
839-
return log_oom();
837+
return free_and_strdup_warn(&arg_root_fstype, value);
840838

841839
} else if (streq(key, "rootflags")) {
842840

@@ -851,24 +849,21 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
851849
if (proc_cmdline_value_missing(key, value))
852850
return 0;
853851

854-
if (free_and_strdup(&arg_root_hash, value) < 0)
855-
return log_oom();
852+
return free_and_strdup_warn(&arg_root_hash, value);
856853

857854
} else if (streq(key, "mount.usr")) {
858855

859856
if (proc_cmdline_value_missing(key, value))
860857
return 0;
861858

862-
if (free_and_strdup(&arg_usr_what, value) < 0)
863-
return log_oom();
859+
return free_and_strdup_warn(&arg_usr_what, value);
864860

865861
} else if (streq(key, "mount.usrfstype")) {
866862

867863
if (proc_cmdline_value_missing(key, value))
868864
return 0;
869865

870-
if (free_and_strdup(&arg_usr_fstype, value) < 0)
871-
return log_oom();
866+
return free_and_strdup_warn(&arg_usr_fstype, value);
872867

873868
} else if (streq(key, "mount.usrflags")) {
874869

src/mount/mount-tool.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,15 @@ static int parse_argv(int argc, char *argv[]) {
241241
break;
242242

243243
case 't':
244-
if (free_and_strdup(&arg_mount_type, optarg) < 0)
245-
return log_oom();
244+
r = free_and_strdup_warn(&arg_mount_type, optarg);
245+
if (r < 0)
246+
return r;
246247
break;
247248

248249
case 'o':
249-
if (free_and_strdup(&arg_mount_options, optarg) < 0)
250-
return log_oom();
250+
r = free_and_strdup_warn(&arg_mount_options, optarg);
251+
if (r < 0)
252+
return r;
251253
break;
252254

253255
case ARG_OWNER: {
@@ -271,8 +273,9 @@ static int parse_argv(int argc, char *argv[]) {
271273
break;
272274

273275
case ARG_DESCRIPTION:
274-
if (free_and_strdup(&arg_description, optarg) < 0)
275-
return log_oom();
276+
r = free_and_strdup_warn(&arg_description, optarg);
277+
if (r < 0)
278+
return r;
276279
break;
277280

278281
case 'p':

src/network/networkd-manager.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,8 +1178,9 @@ int manager_set_hostname(Manager *m, const char *hostname) {
11781178

11791179
log_debug("Setting transient hostname: '%s'", strna(hostname));
11801180

1181-
if (free_and_strdup(&m->dynamic_hostname, hostname) < 0)
1182-
return log_oom();
1181+
r = free_and_strdup_warn(&m->dynamic_hostname, hostname);
1182+
if (r < 0)
1183+
return r;
11831184

11841185
if (!m->bus || sd_bus_is_ready(m->bus) <= 0) {
11851186
log_debug("Not connected to system bus, setting hostname later.");
@@ -1227,8 +1228,9 @@ int manager_set_timezone(Manager *m, const char *tz) {
12271228
assert(tz);
12281229

12291230
log_debug("Setting system timezone: '%s'", tz);
1230-
if (free_and_strdup(&m->dynamic_timezone, tz) < 0)
1231-
return log_oom();
1231+
r = free_and_strdup_warn(&m->dynamic_timezone, tz);
1232+
if (r < 0)
1233+
return r;
12321234

12331235
if (!m->bus || sd_bus_is_ready(m->bus) <= 0) {
12341236
log_debug("Not connected to system bus, setting timezone later.");

src/nspawn/nspawn-settings.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,7 @@ int config_parse_hostname(
706706
return 0;
707707
}
708708

709-
if (free_and_strdup(s, empty_to_null(rvalue)) < 0)
710-
return log_oom();
711-
712-
return 0;
709+
return free_and_strdup_warn(s, empty_to_null(rvalue));
713710
}
714711

715712
int config_parse_oom_score_adjust(

src/run-generator/run-generator.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@ static int parse(const char *key, const char *value, void *data) {
3939
if (proc_cmdline_value_missing(key, value))
4040
return 0;
4141

42-
if (free_and_strdup(&arg_success_action, value) < 0)
43-
return log_oom();
42+
return free_and_strdup_warn(&arg_success_action, value);
4443

4544
} else if (proc_cmdline_key_streq(key, "systemd.run_failure_action")) {
4645

4746
if (proc_cmdline_value_missing(key, value))
4847
return 0;
4948

50-
if (free_and_strdup(&arg_failure_action, value) < 0)
51-
return log_oom();
49+
return free_and_strdup_warn(&arg_failure_action, value);
5250
}
5351

5452
return 0;

src/shared/conf-parser.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,7 @@ int config_parse_string(
731731
assert(rvalue);
732732
assert(data);
733733

734-
if (free_and_strdup(s, empty_to_null(rvalue)) < 0)
735-
return log_oom();
736-
737-
return 0;
734+
return free_and_strdup_warn(s, empty_to_null(rvalue));
738735
}
739736

740737
int config_parse_path(

0 commit comments

Comments
 (0)
X Tutup