Skip to content

Commit 8b9afa5

Browse files
committed
timedate: use cleanup attribute at one more place
1 parent da29de2 commit 8b9afa5

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/timedate/timedated.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,18 @@ static void unit_status_info_clear(UnitStatusInfo *p) {
102102
p->active_state = mfree(p->active_state);
103103
}
104104

105-
static void unit_status_info_free(UnitStatusInfo *p) {
106-
assert(p);
105+
static UnitStatusInfo *unit_status_info_free(UnitStatusInfo *p) {
106+
if (!p)
107+
return NULL;
107108

108109
unit_status_info_clear(p);
109110
free(p->name);
110111
free(p->path);
111-
free(p);
112+
return mfree(p);
112113
}
113114

115+
DEFINE_TRIVIAL_CLEANUP_FUNC(UnitStatusInfo*, unit_status_info_free);
116+
114117
static void context_clear(Context *c) {
115118
UnitStatusInfo *p;
116119

@@ -129,8 +132,13 @@ static void context_clear(Context *c) {
129132
}
130133

131134
static int context_add_ntp_service(Context *c, const char *s, const char *source) {
135+
_cleanup_(unit_status_info_freep) UnitStatusInfo *unit = NULL;
132136
UnitStatusInfo *u;
133137

138+
assert(c);
139+
assert(s);
140+
assert(source);
141+
134142
if (!unit_name_is_valid(s, UNIT_NAME_PLAIN))
135143
return -EINVAL;
136144

@@ -139,18 +147,17 @@ static int context_add_ntp_service(Context *c, const char *s, const char *source
139147
if (streq(u->name, s))
140148
return 0;
141149

142-
u = new0(UnitStatusInfo, 1);
143-
if (!u)
150+
unit = new0(UnitStatusInfo, 1);
151+
if (!unit)
144152
return -ENOMEM;
145153

146-
u->name = strdup(s);
147-
if (!u->name) {
148-
free(u);
154+
unit->name = strdup(s);
155+
if (!unit->name)
149156
return -ENOMEM;
150-
}
151157

152-
LIST_APPEND(units, c->units, u);
153-
log_unit_debug(u, "added from %s.", source);
158+
LIST_APPEND(units, c->units, unit);
159+
log_unit_debug(unit, "added from %s.", source);
160+
TAKE_PTR(unit);
154161

155162
return 0;
156163
}

0 commit comments

Comments
 (0)