From 8658bbe3eed38183554643f93f4c23718fd24827 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Wed, 29 Mar 2017 17:22:18 +0100 Subject: [PATCH] dmfilemapd: always close link check file descriptor (coverity) Similar to 40fb91a, but for the file descriptor opened using the link path reported by /proc//fd/. The daemon opens a new file descriptor from /proc//fd when checking for an unlinked file with mode=inode. Ensure that it is always closed even if the same file test fails. --- daemons/dmfilemapd/dmfilemapd.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/daemons/dmfilemapd/dmfilemapd.c b/daemons/dmfilemapd/dmfilemapd.c index 6e25c5ced..0f3780be9 100644 --- a/daemons/dmfilemapd/dmfilemapd.c +++ b/daemons/dmfilemapd/dmfilemapd.c @@ -600,13 +600,15 @@ check_unlinked: */ if ((fd = open(link_buf, O_RDONLY)) < 0) fm->deleted = 1; - - if ((same = _filemap_monitor_check_same_file(fm->fd, fd)) < 0) - return 0; + else + same = _filemap_monitor_check_same_file(fm->fd, fd); if ((fd > 0) && close(fd)) log_error("Error closing fd %d", fd); + if (same < 0) + return 0; + /* Should not happen with normal /proc. */ if ((fd > 0) && !same) { log_error("File descriptor mismatch: %d and %s (read from %s) "