From nobody Fri Dec 19 04:29:38 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1585575590; cv=none; d=zohomail.com; s=zohoarc; b=R5yCZFosy1aC6kSRz5v3M1YRQdKhPnJSQ+f45EKCf6qJBesjxXk3+PIhh+zc9rQhnh8NgRb4LoI5uzmj7e9YG1dfv+sycWOdx3LjyUDVVtV9rVKRU+3eu5K7Uux83X03ytHOdG6SQzHfhS2h/8PnFA+cP0mfJff6fryjFbyRMjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585575590; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Tzhpk4dwyOYNDStF5ysavvxsRESBLzN5HDwrZYha4/8=; b=ffG3dJ/mtjPSpfIQu8JZHL7O567WgkPRkWQ1taFAtpDj2o7edV9Ka7qSwT2RXc+CG8quWm/e8V04L3lGoACe295EWRtlYYvAZox4kJnmckoH9p3kBwKwmi0m9PQZkB3KyokDWfi7yt6G9OssgZ9Icl5dFE6+QL8QAc3SeU0sW+k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585575590842993.2573593358482; Mon, 30 Mar 2020 06:39:50 -0700 (PDT) Received: from localhost ([::1]:50120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIudp-0000Bw-LD for importer@patchew.org; Mon, 30 Mar 2020 09:39:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49493) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIub3-0004P8-Ai for qemu-devel@nongnu.org; Mon, 30 Mar 2020 09:36:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIub2-0001Ax-7m for qemu-devel@nongnu.org; Mon, 30 Mar 2020 09:36:57 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:53855) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jIub2-00019e-1f for qemu-devel@nongnu.org; Mon, 30 Mar 2020 09:36:56 -0400 Received: by mail-wm1-x32a.google.com with SMTP id b12so19982479wmj.3 for ; Mon, 30 Mar 2020 06:36:55 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id o14sm20756504wmh.22.2020.03.30.06.36.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2020 06:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Tzhpk4dwyOYNDStF5ysavvxsRESBLzN5HDwrZYha4/8=; b=ptlpOOYvB6mk+eUKfTcGMEBgkex5Epg44mYPWz5XwqxkoYN8NSQtgjHDF5Ri9ay+gh 6uhIjifZkJ+twuHQdcyEBVG1axq+UErn9iSFqFsj3q3Vo3gwRV8oVzp0zicvAuTdfz/t AZjVezs5rsn/u3cTz1hcRb2/waQeP9jHDhgzu61FBkNi7VB3i4Rhd/kBoh99SDg0jEqr Kve7T3/myuAb+yvogFtSTDGFqch3gROgU8PVnQoBdgxeDWr4vy+RMJasrvX2upXWeqNk k538NHl1WQHwFVeqS0ZqgibxQwXxzqMrgWGQpVZ5BepfaTTgflv8Z0S+sgaIo1oyd6eZ jETw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Tzhpk4dwyOYNDStF5ysavvxsRESBLzN5HDwrZYha4/8=; b=spqThEpR2NIvw5gmvfTAyRWxdPO3qrbPQxRhQJQkrH+GaO7X7AVppb1Zc2qI5uJS5S TNpuy+GZMx2HN4nqYJUXkpn2zDvuAtqrmdvNSHgi+lWK99ay92vhUzUujFD5Ta9JRkVJ t32CHRsguXvt1rNqwEv2L80vqXi/W6U85H6vZbFJyq3LSgI/gau2vnejuLbAx/j3ywFJ Vm9ufMqU3+IE5h9+HziRycIeCSfNTAB5y2enzIGS98EWaJPpuEWzdm/miKnZI1Rp1AwU aUe7J3sRGhiB5PxnjQwl2cMP98jirY/haTAhEO8HvUKCiPk9Hg5mFG5a4QPP51aJ5JNh Fn7g== X-Gm-Message-State: ANhLgQ0ikw1fTE7QPh+j/PxxDciJUg+pg1GWpY2E4tysmAU+IFa/mYUs io9CaXzFEUojqI39taNx2gqRQVFbV/tZxw== X-Google-Smtp-Source: ADFU+vvifE/z7h0dd5bnLo/nUC2assBgq6XxlAV4AHHcEG9zgCh4cCGL8cEh/ByBhlPRpxJ+lmqg9w== X-Received: by 2002:a05:600c:4410:: with SMTP id u16mr13047793wmn.161.1585575414767; Mon, 30 Mar 2020 06:36:54 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 4/6] hw/arm/xlnx-zynqmp.c: Avoid memory leak in error-return path Date: Mon, 30 Mar 2020 14:36:46 +0100 Message-Id: <20200330133648.22297-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200330133648.22297-1-peter.maydell@linaro.org> References: <20200330133648.22297-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32a 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) In xlnx_zynqmp_realize() if the attempt to realize the SD controller object fails then the error-return path will leak the 'bus_name' string. Fix this by deferring the allocation until after the realize has succeeded. Fixes: Coverity CID 1421911 Signed-off-by: Peter Maydell Reviewed-by: Edgar E. Iglesias Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20200324134947.15384-2-peter.maydell@linaro.org --- hw/arm/xlnx-zynqmp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c index 49f1c8d0de2..a13dbeeacec 100644 --- a/hw/arm/xlnx-zynqmp.c +++ b/hw/arm/xlnx-zynqmp.c @@ -520,7 +520,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error= **errp) sysbus_connect_irq(SYS_BUS_DEVICE(&s->sata), 0, gic_spi[SATA_INTR]); =20 for (i =3D 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) { - char *bus_name =3D g_strdup_printf("sd-bus%d", i); + char *bus_name; SysBusDevice *sbd =3D SYS_BUS_DEVICE(&s->sdhci[i]); Object *sdhci =3D OBJECT(&s->sdhci[i]); =20 @@ -541,6 +541,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error= **errp) sysbus_connect_irq(sbd, 0, gic_spi[sdhci_intr[i]]); =20 /* Alias controller SD bus to the SoC itself */ + bus_name =3D g_strdup_printf("sd-bus%d", i); object_property_add_alias(OBJECT(s), bus_name, sdhci, "sd-bus", &error_abort); g_free(bus_name); --=20 2.20.1