Introduce _cleanup_(unit_freep)

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-03-11 16:33:58 +01:00
parent c70cac548a
commit dc409696cf
4 changed files with 11 additions and 17 deletions
+3 -4
View File
@@ -128,7 +128,7 @@ Unit *unit_new(Manager *m, size_t size) {
}
int unit_new_for_name(Manager *m, size_t size, const char *name, Unit **ret) {
Unit *u;
_cleanup_(unit_freep) Unit *u = NULL;
int r;
u = unit_new(m, size);
@@ -136,12 +136,11 @@ int unit_new_for_name(Manager *m, size_t size, const char *name, Unit **ret) {
return -ENOMEM;
r = unit_add_name(u, name);
if (r < 0) {
unit_free(u);
if (r < 0)
return r;
}
*ret = u;
u = NULL;
return r;
}