summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-07-25 12:29:20 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-07-25 13:51:34 -0400
commit9bb7194019ab62b85f76df2be207d3dac58ed726 (patch)
tree7294990a9a29bd1f7eb9408acf17c01c4919281c
parentf8654baa084e8888bc5ba11e8ef3d9784f955cff (diff)
systemctl: use _cleanup_ for UnitCondition
-rw-r--r--src/systemctl/systemctl.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 44a3708a62..6a0ed79a53 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3484,13 +3484,16 @@ typedef struct UnitCondition {
} UnitCondition;
static void unit_condition_free(UnitCondition *c) {
- assert(c);
+ if (!c)
+ return;
free(c->name);
free(c->param);
free(c);
}
+DEFINE_TRIVIAL_CLEANUP_FUNC(UnitCondition*, unit_condition_free);
+
typedef struct UnitStatusInfo {
const char *id;
const char *load_state;
@@ -4232,7 +4235,7 @@ static int status_property(const char *name, sd_bus_message *m, UnitStatusInfo *
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(sbbsi)", &cond, &trigger, &negate, &param, &state)) > 0) {
- UnitCondition *c;
+ _cleanup_(unit_condition_freep) UnitCondition *c = NULL;
log_debug("%s trigger=%d negate=%d %s →%d", cond, trigger, negate, param, state);
@@ -4241,23 +4244,16 @@ static int status_property(const char *name, sd_bus_message *m, UnitStatusInfo *
return log_oom();
c->name = strdup(cond);
- if (!c->name) {
- free(c);
- return log_oom();
- }
-
c->param = strdup(param);
- if (!c->param) {
- free(c->name);
- free(c);
+ if (!c->name || !c->param)
return log_oom();
- }
c->trigger = trigger;
c->negate = negate;
c->tristate = state;
LIST_PREPEND(conditions, i->conditions, c);
+ c = NULL;
}
if (r < 0)
return bus_log_parse_error(r);