[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 12/38] hw/smbios: Fix leaked fd in save_opt_one() error path
From: |
Michael S. Tsirkin |
Subject: |
[PULL 12/38] hw/smbios: Fix leaked fd in save_opt_one() error path |
Date: |
Tue, 3 Nov 2020 09:34:33 -0500 |
From: Philippe Mathieu-Daudé <philmd@redhat.com>
Fix the following Coverity issue (RESOURCE_LEAK):
CID 1432879: Resource leak
Handle variable fd going out of scope leaks the handle.
Replace a close() call by qemu_close() since the handle is
opened with qemu_open().
Fixes: bb99f4772f5 ("hw/smbios: support loading OEM strings values from a file")
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20201030152742.1553968-1-philmd@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/smbios/smbios.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 8b30906e50..6a3d39793b 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -988,16 +988,18 @@ static int save_opt_one(void *opaque,
if (ret < 0) {
error_setg(errp, "Unable to read from %s: %s",
value, strerror(errno));
+ qemu_close(fd);
return -1;
}
if (memchr(buf, '\0', ret)) {
error_setg(errp, "NUL in OEM strings value in %s", value);
+ qemu_close(fd);
return -1;
}
g_byte_array_append(data, (guint8 *)buf, ret);
}
- close(fd);
+ qemu_close(fd);
*opt->dest = g_renew(char *, *opt->dest, (*opt->ndest) + 1);
(*opt->dest)[*opt->ndest] = (char *)g_byte_array_free(data, FALSE);
--
MST
- [PULL 05/38] memory-device: Support big alignment requirements, (continued)
- [PULL 05/38] memory-device: Support big alignment requirements, Michael S. Tsirkin, 2020/11/03
- [PULL 06/38] memory-device: Add get_min_alignment() callback, Michael S. Tsirkin, 2020/11/03
- [PULL 07/38] virito-mem: Implement get_min_alignment(), Michael S. Tsirkin, 2020/11/03
- [PULL 08/38] hw/acpi : Don't use '#' flag of printf format, Michael S. Tsirkin, 2020/11/03
- [PULL 10/38] hw/acpi : add spaces around operator, Michael S. Tsirkin, 2020/11/03
- [PULL 09/38] hw/acpi : add space before the open parenthesis '(', Michael S. Tsirkin, 2020/11/03
- [PULL 13/38] virtio-iommu: Fix virtio_iommu_mr(), Michael S. Tsirkin, 2020/11/03
- [PULL 11/38] hw/virtio/vhost-backend: Fix Coverity CID 1432871, Michael S. Tsirkin, 2020/11/03
- [PULL 14/38] virtio-iommu: Store memory region in endpoint struct, Michael S. Tsirkin, 2020/11/03
- [PULL 15/38] virtio-iommu: Add memory notifiers for map/unmap, Michael S. Tsirkin, 2020/11/03
- [PULL 12/38] hw/smbios: Fix leaked fd in save_opt_one() error path,
Michael S. Tsirkin <=
- [PULL 17/38] virtio-iommu: Add replay() memory region callback, Michael S. Tsirkin, 2020/11/03
- [PULL 18/38] virtio-iommu: Add notify_flag_changed() memory region callback, Michael S. Tsirkin, 2020/11/03
- [PULL 19/38] memory: Add interface to set iommu page size mask, Michael S. Tsirkin, 2020/11/03
- [PULL 20/38] vfio: Set IOMMU page size as per host supported page size, Michael S. Tsirkin, 2020/11/03
- [PULL 21/38] virtio-iommu: Set supported page size mask, Michael S. Tsirkin, 2020/11/03
- [PULL 22/38] vfio: Don't issue full 2^64 unmap, Michael S. Tsirkin, 2020/11/03
- [PULL 23/38] vhost-vdpa: Add qemu_close in vhost_vdpa_cleanup, Michael S. Tsirkin, 2020/11/03
- [PULL 24/38] net: Add vhost-vdpa in show_netdevs(), Michael S. Tsirkin, 2020/11/03
- [PULL 26/38] vhost-blk: set features before setting inflight feature, Michael S. Tsirkin, 2020/11/03
- [PULL 27/38] libvhost-user: follow QEMU comment style, Michael S. Tsirkin, 2020/11/03