From nobody Thu Nov 6 19:45:38 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542838206049863.7585626100904; Wed, 21 Nov 2018 14:10:06 -0800 (PST) Received: from localhost ([::1]:42566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPahA-00066Q-Ug for importer@patchew.org; Wed, 21 Nov 2018 17:10:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPafD-0004Wj-IX for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPaf9-0002AE-GF for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48504) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPaf8-00028e-MG for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:59 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03F4630024F0; Wed, 21 Nov 2018 22:07:58 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id F25EE5D75C; Wed, 21 Nov 2018 22:07:54 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:26 +0400 Message-Id: <20181121220647.18844-10-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 21 Nov 2018 22:07:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 09/30] net/slirp: fix a few memory leaks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Handle chardev removal on failure to register the forward rule. Free all the guestfwd data on cleanup. Signed-off-by: Marc-Andr=C3=A9 Lureau --- net/slirp.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 9f07923925..6eeb54d7b1 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -75,6 +75,13 @@ struct slirp_config_str { char str[1024]; }; =20 +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; =20 static struct slirp_config_str *slirp_configs; @@ -122,10 +130,19 @@ static void slirp_smb_exit(Notifier *n, void *data) slirp_smb_cleanup(s); } =20 +static void slirp_free_fwd(gpointer data) +{ + struct GuestFwd *fwd =3D data; + + qemu_chr_fe_deinit(&fwd->hd, true); + g_free(data); +} + static void net_slirp_cleanup(NetClientState *nc) { SlirpState *s =3D DO_UPCAST(SlirpState, nc, nc); =20 + 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); @@ -711,13 +728,6 @@ static int slirp_smb(SlirpState* s, const char *export= ed_dir, =20 #endif /* !defined(_WIN32) */ =20 -struct GuestFwd { - CharBackend hd; - struct in_addr server; - int port; - Slirp *slirp; -}; - static int guestfwd_can_read(void *opaque) { struct GuestFwd *fwd =3D opaque; @@ -791,6 +801,7 @@ static int slirp_guestfwd(SlirpState *s, const char *co= nfig_str, Error **errp) qemu_chr_fe_init(&fwd->hd, chr, &err); if (err) { error_propagate(errp, err); + object_unparent(OBJECT(chr)); g_free(fwd); return -1; } @@ -799,6 +810,7 @@ static int slirp_guestfwd(SlirpState *s, const char *co= nfig_str, Error **errp) &server, port) < 0) { error_setg(errp, "Conflicting/invalid host:port in guest " "forwarding rule '%s'", config_str); + qemu_chr_fe_deinit(&fwd->hd, true); g_free(fwd); return -1; } @@ -808,6 +820,7 @@ static int slirp_guestfwd(SlirpState *s, const char *co= nfig_str, Error **errp) =20 qemu_chr_fe_set_handlers(&fwd->hd, guestfwd_can_read, guestfwd_rea= d, NULL, NULL, fwd, NULL, true); + s->fwd =3D g_slist_append(s->fwd, fwd); } return 0; =20 --=20 2.20.0.rc1