diff mbox

xfs_spaceman: close open file for error case in openfile()

Message ID 20170629162530.6023-1-billodo@redhat.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Bill O'Donnell June 29, 2017, 4:25 p.m. UTC
openfile() fails to close the open file in one error case.
Add close(fd) to correct the condition.

Detected by CoverityScan, CID#1413770 (RESOURCE_LEAK)

Signed-off-by: Bill O'Donnell <billodo@redhat.com>
---
 spaceman/file.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Darrick J. Wong June 29, 2017, 4:27 p.m. UTC | #1
On Thu, Jun 29, 2017 at 11:25:30AM -0500, Bill O'Donnell wrote:
> openfile() fails to close the open file in one error case.
> Add close(fd) to correct the condition.
> 
> Detected by CoverityScan, CID#1413770 (RESOURCE_LEAK)
> 
> Signed-off-by: Bill O'Donnell <billodo@redhat.com>

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  spaceman/file.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/spaceman/file.c b/spaceman/file.c
> index 4ab30900..4c13b4a8 100644
> --- a/spaceman/file.c
> +++ b/spaceman/file.c
> @@ -79,6 +79,7 @@ openfile(
>  		if (!fsp) {
>  			fprintf(stderr, _("%s: cannot find mount point."),
>  				path);
> +			close(fd);
>  			return -1;
>  		}
>  		memcpy(fs_path, fsp, sizeof(struct fs_path));
> -- 
> 2.13.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/spaceman/file.c b/spaceman/file.c
index 4ab30900..4c13b4a8 100644
--- a/spaceman/file.c
+++ b/spaceman/file.c
@@ -79,6 +79,7 @@  openfile(
 		if (!fsp) {
 			fprintf(stderr, _("%s: cannot find mount point."),
 				path);
+			close(fd);
 			return -1;
 		}
 		memcpy(fs_path, fsp, sizeof(struct fs_path));