On 09/04/2013 02:12 PM, George McCollister wrote:
> Before my previous patch, journal_file_empty wasn't be called with the
> correct filename. Now that it's being called with the correct filename
> it leaks file descriptors. This patch closes the file descriptors before
> returning.
> 
> Signed-off-by: George McCollister <[email protected]>
> ---
>  src/journal/journal-vacuum.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c
> index ace7722..2cfc73c 100644
> --- a/src/journal/journal-vacuum.c
> +++ b/src/journal/journal-vacuum.c
> @@ -136,12 +136,18 @@ static int journal_file_empty(int dir_fd, const char 
> *name) {
>          if (fd < 0)
>                  return -errno;
>  
> -        if (lseek(fd, offsetof(Header, n_entries), SEEK_SET) < 0)
> +        if (lseek(fd, offsetof(Header, n_entries), SEEK_SET) < 0) {
> +                close(fd);
>                  return -errno;
> +        }
>  
>          r = read(fd, &n_entries, sizeof(n_entries));
> -        if (r != sizeof(n_entries))
> +        if (r != sizeof(n_entries)) {
> +                close(fd);
>                  return r == 0 ? -EINVAL : -errno;
> +        }
> +
> +        close(fd);
>  
>          return le64toh(n_entries) == 0;
>  }
> 

Thanks! Pushed, but with the use of _cleanup_close_
_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to