Merge pull request #8950 from dtardon/cleanup

use automatic cleanup more
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-05-10 17:23:40 +02:00
committed by GitHub
6 changed files with 112 additions and 181 deletions
+46 -58
View File
@@ -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) {
+5 -8
View File
@@ -417,7 +417,8 @@ int strv_env_replace(char ***l, char *p) {
char **strv_env_set(char **x, const char *p) {
char **k, **r;
char **k;
_cleanup_strv_free_ char **r = NULL;
char* m[2] = { (char*) p, NULL };
/* Overrides the env var setting of p, returns a new copy */
@@ -428,18 +429,14 @@ char **strv_env_set(char **x, const char *p) {
k = r;
if (env_append(r, &k, x) < 0)
goto fail;
return NULL;
if (env_append(r, &k, m) < 0)
goto fail;
return NULL;
*k = NULL;
return r;
fail:
strv_free(r);
return NULL;
return TAKE_PTR(r);
}
char *strv_env_get_n(char **l, const char *name, size_t k, unsigned flags) {
+4 -8
View File
@@ -121,7 +121,7 @@ size_t strv_length(char * const *l) {
char **strv_new_ap(const char *x, va_list ap) {
const char *s;
char **a;
_cleanup_strv_free_ char **a = NULL;
size_t n = 0, i = 0;
va_list aq;
@@ -152,7 +152,7 @@ char **strv_new_ap(const char *x, va_list ap) {
if (x != STRV_IGNORE) {
a[i] = strdup(x);
if (!a[i])
goto fail;
return NULL;
i++;
}
@@ -163,7 +163,7 @@ char **strv_new_ap(const char *x, va_list ap) {
a[i] = strdup(s);
if (!a[i])
goto fail;
return NULL;
i++;
}
@@ -171,11 +171,7 @@ char **strv_new_ap(const char *x, va_list ap) {
a[i] = NULL;
return a;
fail:
strv_free(a);
return NULL;
return TAKE_PTR(a);
}
char **strv_new(const char *x, ...) {