summaryrefslogtreecommitdiff
path: root/src/core/path.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-01 17:58:56 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-03 08:55:53 -0500
commita163db44190dea7c34112f28f32cdff664d79b06 (patch)
tree7aa14160b6b6dc1f55fd7c49800dc1a771ee04e3 /src/core/path.c
parentf8c16f42fb6d8e0425ff2b867aa9af07d9b6b4ba (diff)
core/path: use automatic cleanup
... and fix bogus return code on malloc failure.
Diffstat (limited to 'src/core/path.c')
-rw-r--r--src/core/path.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/core/path.c b/src/core/path.c
index 7bbbf1f8eb..65913f8759 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -118,7 +118,7 @@ void path_spec_unwatch(PathSpec *s, Unit *u) {
}
int path_spec_fd_event(PathSpec *s, uint32_t events) {
- uint8_t *buf = NULL;
+ uint8_t _cleanup_free_ *buf = NULL;
struct inotify_event *e;
ssize_t k;
int l;
@@ -126,30 +126,24 @@ int path_spec_fd_event(PathSpec *s, uint32_t events) {
if (events != EPOLLIN) {
log_error("Got invalid poll event on inotify.");
- r = -EINVAL;
- goto out;
+ return -EINVAL;
}
if (ioctl(s->inotify_fd, FIONREAD, &l) < 0) {
log_error("FIONREAD failed: %m");
- r = -errno;
- goto out;
+ return -errno;
}
assert(l > 0);
buf = malloc(l);
- if (!buf) {
- log_error("Failed to allocate buffer: %m");
- r = -errno;
- goto out;
- }
+ if (!buf)
+ return log_oom();
k = read(s->inotify_fd, buf, l);
if (k < 0) {
log_error("Failed to read inotify event: %m");
- r = -errno;
- goto out;
+ return -errno;
}
e = (struct inotify_event*) buf;
@@ -167,8 +161,7 @@ int path_spec_fd_event(PathSpec *s, uint32_t events) {
e = (struct inotify_event*) ((uint8_t*) e + step);
k -= step;
}
-out:
- free(buf);
+
return r;
}