From: David Tardon Date: Thu, 10 May 2018 12:04:30 +0000 (+0200) Subject: basic: use automatic cleanup more X-Git-Tag: v239~285^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=921b59871649381def508e2646a959f0c69bd005;p=thirdparty%2Fsystemd.git basic: use automatic cleanup more --- diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index a30de78dc23..4cf21100cc9 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -891,7 +891,7 @@ fail: int calendar_spec_from_string(const char *p, CalendarSpec **spec) { const char *utc; - CalendarSpec *c; + _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL; int r; assert(p); @@ -939,58 +939,54 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) { last_space = strrchr(p, ' '); if (last_space != NULL && timezone_is_valid(last_space + 1)) { c->timezone = strdup(last_space + 1); - if (!c->timezone) { - r = -ENOMEM; - goto fail; - } + if (!c->timezone) + return -ENOMEM; p = strndupa(p, last_space - p); } } } - if (isempty(p)) { - r = -EINVAL; - goto fail; - } + if (isempty(p)) + return -EINVAL; if (strcaseeq(p, "minutely")) { r = const_chain(0, &c->microsecond); if (r < 0) - goto fail; + return r; } else if (strcaseeq(p, "hourly")) { r = const_chain(0, &c->minute); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->microsecond); if (r < 0) - goto fail; + return r; } else if (strcaseeq(p, "daily")) { r = const_chain(0, &c->hour); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->minute); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->microsecond); if (r < 0) - goto fail; + return r; } else if (strcaseeq(p, "monthly")) { r = const_chain(1, &c->day); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->hour); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->minute); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->microsecond); if (r < 0) - goto fail; + return r; } else if (strcaseeq(p, "annually") || strcaseeq(p, "yearly") || @@ -998,19 +994,19 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) { r = const_chain(1, &c->month); if (r < 0) - goto fail; + return r; r = const_chain(1, &c->day); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->hour); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->minute); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->microsecond); if (r < 0) - goto fail; + return r; } else if (strcaseeq(p, "weekly")) { @@ -1018,40 +1014,40 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) { r = const_chain(0, &c->hour); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->minute); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->microsecond); if (r < 0) - goto fail; + return r; } else if (strcaseeq(p, "quarterly")) { r = const_chain(1, &c->month); if (r < 0) - goto fail; + return r; r = const_chain(4, &c->month); if (r < 0) - goto fail; + return r; r = const_chain(7, &c->month); if (r < 0) - goto fail; + return r; r = const_chain(10, &c->month); if (r < 0) - goto fail; + return r; r = const_chain(1, &c->day); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->hour); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->minute); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->microsecond); if (r < 0) - goto fail; + return r; } else if (strcaseeq(p, "biannually") || strcaseeq(p, "bi-annually") || @@ -1060,59 +1056,51 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) { r = const_chain(1, &c->month); if (r < 0) - goto fail; + return r; r = const_chain(7, &c->month); if (r < 0) - goto fail; + return r; r = const_chain(1, &c->day); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->hour); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->minute); if (r < 0) - goto fail; + return r; r = const_chain(0, &c->microsecond); if (r < 0) - goto fail; + return r; } else { r = parse_weekdays(&p, c); if (r < 0) - goto fail; + return r; r = parse_date(&p, c); if (r < 0) - goto fail; + return r; if (r == 0) { r = parse_calendar_time(&p, c); if (r < 0) - goto fail; + return r; } - if (*p != 0) { - r = -EINVAL; - goto fail; - } + if (*p != 0) + return -EINVAL; } r = calendar_spec_normalize(c); if (r < 0) - goto fail; + return r; - if (!calendar_spec_valid(c)) { - r = -EINVAL; - goto fail; - } + if (!calendar_spec_valid(c)) + return -EINVAL; - *spec = c; + *spec = TAKE_PTR(c); return 0; - -fail: - calendar_spec_free(c); - return r; } static int find_end_of_month(struct tm *tm, bool utc, int day) { diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index d2a4c18bb86..a78039bb4fa 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -1637,7 +1637,7 @@ int config_parse_timer(const char *unit, usec_t usec = 0; TimerValue *v; TimerBase b; - CalendarSpec *c = NULL; + _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL; Unit *u = userdata; _cleanup_free_ char *k = NULL; int r; @@ -1678,14 +1678,12 @@ int config_parse_timer(const char *unit, } v = new0(TimerValue, 1); - if (!v) { - calendar_spec_free(c); + if (!v) return log_oom(); - } v->base = b; v->value = usec; - v->calendar_spec = c; + v->calendar_spec = TAKE_PTR(c); LIST_PREPEND(value, t->values, v);