[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 6/6] tap: fix memory leak on failure in net_init_tap(
From: |
Jason Wang |
Subject: |
[Qemu-devel] [PULL 6/6] tap: fix memory leak on failure in net_init_tap() |
Date: |
Fri, 20 Jan 2017 11:07:50 +0800 |
From: Peter Maydell <address@hidden>
Commit 091a6b2ac fixed most of the memory leaks in failure
paths in net_init_tap() reported by Coverity (CID 1356216),
but missed one. Fix it by deferring the allocation of
fds and vhost_fds until after the error check.
Signed-off-by: Peter Maydell <address@hidden>
Signed-off-by: Jason Wang <address@hidden>
---
net/tap.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index b6896a7..6248e85 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -788,8 +788,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
return -1;
}
} else if (tap->has_fds) {
- char **fds = g_new0(char *, MAX_TAP_QUEUES);
- char **vhost_fds = g_new0(char *, MAX_TAP_QUEUES);
+ char **fds;
+ char **vhost_fds;
int nfds, nvhosts;
if (tap->has_ifname || tap->has_script || tap->has_downscript ||
@@ -801,6 +801,9 @@ int net_init_tap(const Netdev *netdev, const char *name,
return -1;
}
+ fds = g_new0(char *, MAX_TAP_QUEUES);
+ vhost_fds = g_new0(char *, MAX_TAP_QUEUES);
+
nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES);
if (tap->has_vhostfds) {
nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);
--
2.7.4
- [Qemu-devel] [PULL 0/6] Net patches, Jason Wang, 2017/01/19
- [Qemu-devel] [PULL 1/6] docs: Fix description of the sentence, Jason Wang, 2017/01/19
- [Qemu-devel] [PULL 2/6] net: optimize checksum computation, Jason Wang, 2017/01/19
- [Qemu-devel] [PULL 3/6] m68k: QOMify the MCF Fast Ethernet Controller device, Jason Wang, 2017/01/19
- [Qemu-devel] [PULL 5/6] hw/pci: use-after-free in pci_nic_init_nofail when nic device fails to initialize, Jason Wang, 2017/01/19
- [Qemu-devel] [PULL 4/6] hw/net/dp8393x: Avoid unintentional sign extensions on addresses, Jason Wang, 2017/01/19
- [Qemu-devel] [PULL 6/6] tap: fix memory leak on failure in net_init_tap(),
Jason Wang <=
- Re: [Qemu-devel] [PULL 0/6] Net patches, Peter Maydell, 2017/01/20