From nobody Wed Nov 12 00:13:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1566973653; cv=none; d=zoho.com; s=zohoarc; b=V782DVXqHVWNqNlfjXu4kbNFqO6H0sLbRNhfUtkiyI9dlLQIkAtGS6kr40XxD3tikhTbhhJH0FH7GWs8wVG2TmqrLvJ7C7iVCUQSi0aIvf9aw2lyGfZId4OS5uhMl4LrSMJCRHAn5wbSdAEX+JEfB2imSFyNsF7QLOKr/4KmnIc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566973653; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=tG3mr5uG8giLr57k6o6F/DbjmaA+58DFd+m1xvVxGeM=; b=LfFkP12jPqwrXods2os+wC/Q384g710ZWEoqOvXtpyYV/TMDQCjt8oTzPxTtU4ogp1WxkNoMafyUQaAiVV5wh9gieJPjjUb58TCqGhq1vjffptuC0h9jFLCzTj/W5GuB/L4J/etJZiCF5RF9A0wVVo3dkm1PHCnZcIaObsV6w9s= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566973653666313.28174004632706; Tue, 27 Aug 2019 23:27:33 -0700 (PDT) Received: from localhost ([::1]:33080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2rQa-0002nh-KG for importer@patchew.org; Wed, 28 Aug 2019 02:27:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41628) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2rPA-0001xX-LZ for qemu-devel@nongnu.org; Wed, 28 Aug 2019 02:26:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i2rP9-0005op-CH for qemu-devel@nongnu.org; Wed, 28 Aug 2019 02:26:04 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2190 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i2rP9-0005mU-2E for qemu-devel@nongnu.org; Wed, 28 Aug 2019 02:26:03 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 62C6BDA8E3D67DB3B66D; Wed, 28 Aug 2019 14:25:58 +0800 (CST) Received: from localhost (10.133.205.53) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.439.0; Wed, 28 Aug 2019 14:25:47 +0800 From: Ying Fang To: , Date: Wed, 28 Aug 2019 14:25:35 +0800 Message-ID: <20190828062535.1573-1-fangying1@huawei.com> X-Mailer: git-send-email 2.22.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.133.205.53] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.190 Subject: [Qemu-devel] [PATCH] xhci: Fix memory leak in xhci_kick_epctx X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fangying , zhouyibo3@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: fangying Address Sanitizer shows memory leak in xhci_kick_epctx hw/usb/hcd-xhci.c:19= 12. A sglist is leaked when a packet is retired and returns USB_RET_NAK status. The leak stack is as bellow: Direct leak of 2688 byte(s) in 168 object(s) allocated from: #0 0xffffae8b11db in __interceptor_malloc (/lib64/libasan.so.4+0xd31db) #1 0xffffae5c9163 in g_malloc (/lib64/libglib-2.0.so.0+0x57163) #2 0xaaaabb6fb3f7 in qemu_sglist_init dma-helpers.c:43 #3 0xaaaabba705a7 in pci_dma_sglist_init include/hw/pci/pci.h:837 #4 0xaaaabba705a7 in xhci_xfer_create_sgl hw/usb/hcd-xhci.c:1443 #5 0xaaaabba705a7 in xhci_setup_packet hw/usb/hcd-xhci.c:1615 #6 0xaaaabba77a6f in xhci_kick_epctx hw/usb/hcd-xhci.c:1912 #7 0xaaaabbdaad27 in timerlist_run_timers util/qemu-timer.c:592 #8 0xaaaabbdab19f in qemu_clock_run_timers util/qemu-timer.c:606 #9 0xaaaabbdab19f in qemu_clock_run_all_timers util/qemu-timer.c:692 #10 0xaaaabbdab9a3 in main_loop_wait util/main-loop.c:524 #11 0xaaaabb6ff5e7 in main_loop vl.c:1806 #12 0xaaaabb1e1453 in main vl.c:4488 Signed-off-by: Ying Fang --- hw/usb/hcd-xhci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index f578264..2d85d8f 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -1914,6 +1914,7 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, uns= igned int streamid) } usb_handle_packet(xfer->packet.ep->dev, &xfer->packet); if (xfer->packet.status =3D=3D USB_RET_NAK) { + xhci_xfer_unmap(xfer); return; } xhci_try_complete_packet(xfer); --=20 1.8.3.1