From 4efcc1f02ed22d5ca41f2a565ec9651ed997a8e8 Mon Sep 17 00:00:00 2001
From: Fam Zheng <famz@redhat.com>
Date: Wed, 22 Mar 2017 23:51:09 +0100
Subject: [PATCH 12/12] file-posix: Don't leak fd in hdev_get_max_segments

RH-Author: Fam Zheng <famz@redhat.com>
Message-id: <20170322235109.24122-4-famz@redhat.com>
Patchwork-id: 74434
O-Subject: [RHEV-7.3.z qemu-kvm-rhev PATCH v2 3/3] file-posix: Don't leak fd in hdev_get_max_segments
Bugzilla: 1431149
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Markus Armbruster <armbru@redhat.com>

This fixes a leaked fd introduced in commit 9103f1ce.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit fed414df9dc9abef040adfbd8c5956fb610edaa2)
Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 block/raw-posix.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index ce9d113..f975dba 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -777,6 +777,9 @@ static int hdev_get_max_segments(const struct stat *st)
     }
 
 out:
+    if (fd != -1) {
+        close(fd);
+    }
     g_free(sysfspath);
     return ret;
 #else
-- 
1.8.3.1

