Skip to content

Commit 9bb7194

Browse files
committed
systemctl: use _cleanup_ for UnitCondition
1 parent f8654ba commit 9bb7194

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/systemctl/systemctl.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3484,13 +3484,16 @@ typedef struct UnitCondition {
34843484
} UnitCondition;
34853485

34863486
static void unit_condition_free(UnitCondition *c) {
3487-
assert(c);
3487+
if (!c)
3488+
return;
34883489

34893490
free(c->name);
34903491
free(c->param);
34913492
free(c);
34923493
}
34933494

3495+
DEFINE_TRIVIAL_CLEANUP_FUNC(UnitCondition*, unit_condition_free);
3496+
34943497
typedef struct UnitStatusInfo {
34953498
const char *id;
34963499
const char *load_state;
@@ -4232,7 +4235,7 @@ static int status_property(const char *name, sd_bus_message *m, UnitStatusInfo *
42324235
return bus_log_parse_error(r);
42334236

42344237
while ((r = sd_bus_message_read(m, "(sbbsi)", &cond, &trigger, &negate, &param, &state)) > 0) {
4235-
UnitCondition *c;
4238+
_cleanup_(unit_condition_freep) UnitCondition *c = NULL;
42364239

42374240
log_debug("%s trigger=%d negate=%d %s →%d", cond, trigger, negate, param, state);
42384241

@@ -4241,23 +4244,16 @@ static int status_property(const char *name, sd_bus_message *m, UnitStatusInfo *
42414244
return log_oom();
42424245

42434246
c->name = strdup(cond);
4244-
if (!c->name) {
4245-
free(c);
4246-
return log_oom();
4247-
}
4248-
42494247
c->param = strdup(param);
4250-
if (!c->param) {
4251-
free(c->name);
4252-
free(c);
4248+
if (!c->name || !c->param)
42534249
return log_oom();
4254-
}
42554250

42564251
c->trigger = trigger;
42574252
c->negate = negate;
42584253
c->tristate = state;
42594254

42604255
LIST_PREPEND(conditions, i->conditions, c);
4256+
c = NULL;
42614257
}
42624258
if (r < 0)
42634259
return bus_log_parse_error(r);

0 commit comments

Comments
 (0)