[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/24] Correctly free nd structure
From: |
Mark McLoughlin |
Subject: |
[Qemu-devel] [PATCH 04/24] Correctly free nd structure |
Date: |
Wed, 23 Sep 2009 11:24:03 +0100 |
From: Glauber Costa <address@hidden>
When we "free" a NICInfo structure, we can leak pointers, since we don't do
much more than setting used = 0.
We free() the model parameter, but we don't set it to NULL. This means that
a new user of this structure will see garbage in there. It was not noticed
before because reusing a NICInfo is not that common, but it can be, for
users of device pci hotplug.
A user hit it, described at https://bugzilla.redhat.com/524022
This patch memset's the whole structure, guaranteeing that anyone reusing it
will see a fresh NICinfo. Also, we free some other strings that are currently
leaking.
This codebase is quite old, so this patch should feed all stable trees.
Signed-off-by: Glauber Costa <address@hidden>
Signed-off-by: Mark McLoughlin <address@hidden>
---
net.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/net.c b/net.c
index d04b6bd..422ef4c 100644
--- a/net.c
+++ b/net.c
@@ -2434,6 +2434,7 @@ int net_client_init(Monitor *mon, const char *device,
const char *p)
goto out;
}
nd = &nd_table[idx];
+ memset(nd, 0, sizeof(*nd));
macaddr = nd->macaddr;
macaddr[0] = 0x52;
macaddr[1] = 0x54;
@@ -2803,8 +2804,13 @@ void net_client_uninit(NICInfo *nd)
{
nd->vlan->nb_guest_devs--;
nb_nics--;
- nd->used = 0;
+
qemu_free(nd->model);
+ qemu_free(nd->name);
+ qemu_free(nd->devaddr);
+ qemu_free(nd->id);
+
+ nd->used = 0;
}
static int net_host_check_device(const char *device)
--
1.6.2.5
- [Qemu-devel] [PATCH 00/19 v2] Port -net to QemuOpts, Mark McLoughlin, 2009/09/23
- [Qemu-devel] [PATCH 01/24] Use qemu_strdup() for NICInfo string fields, Mark McLoughlin, 2009/09/23
- [Qemu-devel] [PATCH 04/24] Correctly free nd structure,
Mark McLoughlin <=
- [Qemu-devel] [PATCH 20/24] Clean up legacy code in net_client_init(), Mark McLoughlin, 2009/09/23
- [Qemu-devel] [PATCH 11/24] Add qemu_opts_validate() for post parsing validation, Mark McLoughlin, 2009/09/23
- [Qemu-devel] [PATCH 02/24] Don't assign a static string to NICInfo::model, Mark McLoughlin, 2009/09/23
- [Qemu-devel] [PATCH 03/24] Make NICInfo string fields non-const, Mark McLoughlin, 2009/09/23
- [Qemu-devel] [PATCH 10/24] Make qemu_opts_parse() handle empty strings, Mark McLoughlin, 2009/09/23
- [Qemu-devel] [PATCH 09/24] Remove double error message for -device option parsing, Mark McLoughlin, 2009/09/23
- [Qemu-devel] [PATCH 13/24] Add qemu_net_opts, Mark McLoughlin, 2009/09/23
- [Qemu-devel] [PATCH 23/24] Port PCI NIC hotplug to QemuOpts, Mark McLoughlin, 2009/09/23
- [Qemu-devel] [PATCH 06/24] Fix coding style issue, Mark McLoughlin, 2009/09/23
- [Qemu-devel] [PATCH 08/24] Remove double error message in qemu_option_set(), Mark McLoughlin, 2009/09/23