1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-05 23:51:28 +03:00

core/path: use automatic cleanup

... and fix bogus return code on malloc failure.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2013-03-01 17:58:56 -05:00
parent f8c16f42fb
commit a163db4419

View File

@ -118,7 +118,7 @@ void path_spec_unwatch(PathSpec *s, Unit *u) {
} }
int path_spec_fd_event(PathSpec *s, uint32_t events) { int path_spec_fd_event(PathSpec *s, uint32_t events) {
uint8_t *buf = NULL; uint8_t _cleanup_free_ *buf = NULL;
struct inotify_event *e; struct inotify_event *e;
ssize_t k; ssize_t k;
int l; int l;
@ -126,30 +126,24 @@ int path_spec_fd_event(PathSpec *s, uint32_t events) {
if (events != EPOLLIN) { if (events != EPOLLIN) {
log_error("Got invalid poll event on inotify."); log_error("Got invalid poll event on inotify.");
r = -EINVAL; return -EINVAL;
goto out;
} }
if (ioctl(s->inotify_fd, FIONREAD, &l) < 0) { if (ioctl(s->inotify_fd, FIONREAD, &l) < 0) {
log_error("FIONREAD failed: %m"); log_error("FIONREAD failed: %m");
r = -errno; return -errno;
goto out;
} }
assert(l > 0); assert(l > 0);
buf = malloc(l); buf = malloc(l);
if (!buf) { if (!buf)
log_error("Failed to allocate buffer: %m"); return log_oom();
r = -errno;
goto out;
}
k = read(s->inotify_fd, buf, l); k = read(s->inotify_fd, buf, l);
if (k < 0) { if (k < 0) {
log_error("Failed to read inotify event: %m"); log_error("Failed to read inotify event: %m");
r = -errno; return -errno;
goto out;
} }
e = (struct inotify_event*) buf; 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); e = (struct inotify_event*) ((uint8_t*) e + step);
k -= step; k -= step;
} }
out:
free(buf);
return r; return r;
} }