aboutsummaryrefslogtreecommitdiff
path: root/net/net.c
diff options
context:
space:
mode:
authorJason Wang <jasowang@redhat.com>2013-01-30 19:12:27 +0800
committerAnthony Liguori <aliguori@us.ibm.com>2013-02-01 11:03:01 -0600
commitf7860455fd582b171e526b4b4647b9b9c9a3e703 (patch)
tree648b3fb676ff493f49fb3dddd181687777f81562 /net/net.c
parent18a1541a8da40271056aab99100bdc38283c42ac (diff)
net: introduce NetClientState destructor
To allow allocating an array of NetClientState and free it once, this patch introduces destructor of NetClientState. Which could do type specific free, which could be used by multiqueue to free the array once. Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'net/net.c')
-rw-r--r--net/net.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/net/net.c b/net/net.c
index 3a5bdf6b3f..98a1934b62 100644
--- a/net/net.c
+++ b/net/net.c
@@ -182,11 +182,17 @@ static char *assign_name(NetClientState *nc1, const char *model)
return g_strdup(buf);
}
+static void qemu_net_client_destructor(NetClientState *nc)
+{
+ g_free(nc);
+}
+
static void qemu_net_client_setup(NetClientState *nc,
NetClientInfo *info,
NetClientState *peer,
const char *model,
- const char *name)
+ const char *name,
+ NetClientDestructor *destructor)
{
nc->info = info;
nc->model = g_strdup(model);
@@ -204,7 +210,7 @@ static void qemu_net_client_setup(NetClientState *nc,
QTAILQ_INSERT_TAIL(&net_clients, nc, next);
nc->send_queue = qemu_new_net_queue(nc);
-
+ nc->destructor = destructor;
}
NetClientState *qemu_new_net_client(NetClientInfo *info,
@@ -217,7 +223,8 @@ NetClientState *qemu_new_net_client(NetClientInfo *info,
assert(info->size >= sizeof(NetClientState));
nc = g_malloc0(info->size);
- qemu_net_client_setup(nc, info, peer, model, name);
+ qemu_net_client_setup(nc, info, peer, model, name,
+ qemu_net_client_destructor);
return nc;
}
@@ -279,7 +286,9 @@ static void qemu_free_net_client(NetClientState *nc)
}
g_free(nc->name);
g_free(nc->model);
- g_free(nc);
+ if (nc->destructor) {
+ nc->destructor(nc);
+ }
}
void qemu_del_net_client(NetClientState *nc)