summaryrefslogtreecommitdiff
path: root/src/core/path.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-01 17:44:25 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-03 08:55:53 -0500
commitf8c16f42fb6d8e0425ff2b867aa9af07d9b6b4ba (patch)
tree4c654cc1cd1040a7595a6a252fcb810c9a291ee0 /src/core/path.c
parentb8fe3faf9fa6b95ca0413e7dbe0bbdc1d6ab4d7c (diff)
core/path: fix a leak in success path
... and use automatic cleanup.
Diffstat (limited to 'src/core/path.c')
-rw-r--r--src/core/path.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/core/path.c b/src/core/path.c
index 3775577bcf..7bbbf1f8eb 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -33,6 +33,7 @@
#include "special.h"
#include "bus-errors.h"
#include "path-util.h"
+#include "macro.h"
static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
[PATH_DEAD] = UNIT_INACTIVE,
@@ -52,7 +53,8 @@ int path_spec_watch(PathSpec *s, Unit *u) {
};
bool exists = false;
- char *k, *slash;
+ char _cleanup_free_ *k = NULL;
+ char *slash;
int r;
assert(u);
@@ -60,18 +62,19 @@ int path_spec_watch(PathSpec *s, Unit *u) {
path_spec_unwatch(s, u);
- if (!(k = strdup(s->path)))
+ k = strdup(s->path);
+ if (!k)
return -ENOMEM;
- if ((s->inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC)) < 0) {
+ s->inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
+ if (s->inotify_fd < 0) {
r = -errno;
goto fail;
}
- if (unit_watch_fd(u, s->inotify_fd, EPOLLIN, &s->watch) < 0) {
- r = -errno;
+ r = unit_watch_fd(u, s->inotify_fd, EPOLLIN, &s->watch);
+ if (r < 0)
goto fail;
- }
s->primary_wd = inotify_add_watch(s->inotify_fd, k, flags_table[s->type]);
if (s->primary_wd >= 0)
@@ -99,8 +102,6 @@ int path_spec_watch(PathSpec *s, Unit *u) {
return 0;
fail:
- free(k);
-
path_spec_unwatch(s, u);
return r;
}