From 8d45a3b946b6362ed14c60b81743ca97e44d7869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 17 Jan 2019 15:43:35 +0400 Subject: net/slirp: free forwarding rules on cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'net') diff --git a/net/slirp.c b/net/slirp.c index b91741b8fc..750105a466 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -75,6 +75,13 @@ struct slirp_config_str { char str[1024]; }; +struct GuestFwd { + CharBackend hd; + struct in_addr server; + int port; + Slirp *slirp; +}; + typedef struct SlirpState { NetClientState nc; QTAILQ_ENTRY(SlirpState) entry; @@ -83,6 +90,7 @@ typedef struct SlirpState { #ifndef _WIN32 gchar *smb_dir; #endif + GSList *fwd; } SlirpState; static struct slirp_config_str *slirp_configs; @@ -122,10 +130,19 @@ static void slirp_smb_exit(Notifier *n, void *data) slirp_smb_cleanup(s); } +static void slirp_free_fwd(gpointer data) +{ + struct GuestFwd *fwd = data; + + qemu_chr_fe_deinit(&fwd->hd, true); + g_free(data); +} + static void net_slirp_cleanup(NetClientState *nc) { SlirpState *s = DO_UPCAST(SlirpState, nc, nc); + g_slist_free_full(s->fwd, slirp_free_fwd); slirp_cleanup(s->slirp); if (s->exit_notifier.notify) { qemu_remove_exit_notifier(&s->exit_notifier); @@ -717,13 +734,6 @@ static int slirp_smb(SlirpState* s, const char *exported_dir, #endif /* !defined(_WIN32) */ -struct GuestFwd { - CharBackend hd; - struct in_addr server; - int port; - Slirp *slirp; -}; - static int guestfwd_can_read(void *opaque) { struct GuestFwd *fwd = opaque; @@ -814,6 +824,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp) qemu_chr_fe_set_handlers(&fwd->hd, guestfwd_can_read, guestfwd_read, NULL, NULL, fwd, NULL, true); + s->fwd = g_slist_append(s->fwd, fwd); } return 0; -- cgit v1.2.3