From 8748c6cedcd5d2d9c23a1c4b5aa019c82b735f90 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 21 Jun 2007 17:08:38 +0200 Subject: 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 --- inotail.c | 8 ++++---- 1 file 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; } -- cgit v1.2.3-54-g00ecf