summaryrefslogtreecommitdiff
path: root/inotail.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-06-21 17:08:38 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-06-21 17:08:38 +0200
commit8748c6cedcd5d2d9c23a1c4b5aa019c82b735f90 (patch)
tree08e8dc6520997bd8f9e229f97c00434c260e43ca /inotail.c
parent30282557d1e76a43b804d868b121cd640fcc99ba (diff)
inotail.c: Reorder emalloc/free in handle_inotify_event()
Get rid of the following warning when compiling with -Os: inotail.c:338: warning: 'fbuf' may be used uninitialized in this function
Diffstat (limited to 'inotail.c')
-rw-r--r--inotail.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/inotail.c b/inotail.c
index 8561054..6a000f7 100644
--- a/inotail.c
+++ b/inotail.c
@@ -335,15 +335,13 @@ static int tail_file(struct file_struct *f, unsigned long n_units, char mode, ch
static int handle_inotify_event(struct inotify_event *inev, struct file_struct *f)
{
- char *fbuf;
int ret = 0;
if (inev->mask & IN_MODIFY) {
+ char *fbuf;
ssize_t rc;
struct stat finfo;
- fbuf = emalloc(f->st_blksize);
-
if (verbose)
write_header(f->name);
@@ -354,12 +352,15 @@ static int handle_inotify_event(struct inotify_event *inev, struct file_struct *
goto ignore;
}
+ fbuf = emalloc(f->st_blksize);
+
while ((rc = read(f->fd, fbuf, f->st_blksize)) != 0)
write(STDOUT_FILENO, fbuf, (size_t) rc);
if (fstat(f->fd, &finfo) < 0) {
fprintf(stderr, "Error: Could not stat file '%s' (%s)\n", f->name, strerror(errno));
ret = -1;
+ free(fbuf);
goto ignore;
}
@@ -378,7 +379,6 @@ static int handle_inotify_event(struct inotify_event *inev, struct file_struct *
ignore:
ignore_file(f);
- free(fbuf);
return ret;
}