summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2012-09-19 17:06:28 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2012-10-29 09:01:20 +0000
commit170ca19e4dc2d0513419c2c899e60858761df043 (patch)
treefc6f4b8d90c3ac33f32fe09bb77555ed25221fe0
parentdf326b8463cddbaca31962015358badd209e7501 (diff)
swap: use automatic cleanup
-rw-r--r--src/core/swap.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/core/swap.c b/src/core/swap.c
index 7e1d4371c6..76ab962a17 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -213,17 +213,16 @@ static int swap_add_default_dependencies(Swap *s) {
static int swap_verify(Swap *s) {
bool b;
- char *e;
+ char _cleanup_free_ *e = NULL;
if (UNIT(s)->load_state != UNIT_LOADED)
return 0;
- if (!(e = unit_name_from_path(s->what, ".swap")))
- return -ENOMEM;
+ e = unit_name_from_path(s->what, ".swap");
+ if (e == NULL)
+ return log_oom();
b = unit_has_name(UNIT(s), e);
- free(e);
-
if (!b) {
log_error("%s: Value of \"What\" and unit name do not match, not loading.\n", UNIT(s)->id);
return -EINVAL;
@@ -304,7 +303,8 @@ static int swap_add_one(
bool set_flags) {
Unit *u = NULL;
- char *e = NULL, *wp = NULL;
+ char _cleanup_free_ *e = NULL;
+ char *wp = NULL;
bool delete = false;
int r;
SwapParameters *p;
@@ -316,7 +316,7 @@ static int swap_add_one(
e = unit_name_from_path(what, ".swap");
if (!e)
- return -ENOMEM;
+ return log_oom();
u = manager_get_unit(m, e);
@@ -329,10 +329,8 @@ static int swap_add_one(
delete = true;
u = unit_new(m, sizeof(Swap));
- if (!u) {
- free(e);
- return -ENOMEM;
- }
+ if (!u)
+ return log_oom();
r = unit_add_name(u, e);
if (r < 0)
@@ -385,15 +383,12 @@ static int swap_add_one(
unit_add_to_dbus_queue(u);
- free(e);
-
return 0;
fail:
log_warning("Failed to load swap unit: %s", strerror(-r));
free(wp);
- free(e);
if (delete && u)
unit_free(u);