From nobody Mon Feb 9 10:52:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604071670; cv=none; d=zohomail.com; s=zohoarc; b=WPtXRarkoHLt5qLUiq+DG643Mn58ULXpkuQTjavoBX9gPeRCm6owSm6YIhm7kTxc2BIHP8SLqwjYA0huTjU2tHdtz0hDD1XjQ3p4bk/KGlNb3TVZ9pZ1+eAlnkhxwRC8orbMHJB6nnDDtqOeMOcIgezy8ZbFSkLI1Iauy51lkDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604071670; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=ODLpRQSBoXdl2bHweXJxYHi5dpQs8FLpRt3OFMg34a8=; b=cGNu9NMJS35s/Ebw8VnF+oI3fQI4fq3AjI4+m6qm6JbvYgxmXA4WffvijWRdH0DT9fIGrLNY/pZbYsJNWqsn0P6mKWqnLbkRUR+h0vR93wbWF0J1vGM+VFx6S3OXCaqDmxxtggSyI8BiCH6F4NFKp+0BNfTYKOvL3lDp/xasNo4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1604071670174612.5381417542696; Fri, 30 Oct 2020 08:27:50 -0700 (PDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-375-oMLQCsmqNZOtJbsWZ0E02A-1; Fri, 30 Oct 2020 11:27:47 -0400 Received: by mail-wm1-f72.google.com with SMTP id t201so1377542wmt.1 for ; Fri, 30 Oct 2020 08:27:46 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (234.red-83-42-66.dynamicip.rima-tde.net. [83.42.66.234]) by smtp.gmail.com with ESMTPSA id f20sm5123247wmc.26.2020.10.30.08.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 08:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604071668; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ODLpRQSBoXdl2bHweXJxYHi5dpQs8FLpRt3OFMg34a8=; b=X7LLTtRnQIFis9d7cqwqH/rm9/QQKHXsOd5fGHHtLMepY5anHlJKe5SGTOr/F27MI1WySl 1mAcF78TokHH3Qbrbc5icrkroIakK1ZFuNy8qJw3EyaH7gPA+zc4MJZVsLC2o9tlRehbj/ vrT9yHdQxqtgR3irtQwMbDX94sJzIs8= X-MC-Unique: oMLQCsmqNZOtJbsWZ0E02A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ODLpRQSBoXdl2bHweXJxYHi5dpQs8FLpRt3OFMg34a8=; b=JqBnmEP5+coVjaGvjXW7Tq4sfcIY3AQE9v6QPCHMG93YblcXyEUoK2z6g/sFqZm7eL S2KKofrDo1ESXJ48/uCHPKWNg7VJ0DS6PXXnSmcRZe/lmhkKCNG/WKKM8NTiQlTEePyh KQKmeMRGGz8NrGBr9gH5+CDpm4OoO5jMk2/9MaT9EJIH0qfivPLqN/WMudtc90etLU83 Am8Jd8MKdx0uxJKpp7ssuueOCvRD1oyk/YPxOab/byKhGDAwHX17ZRpEDs4MSYSMe4Vx Wnooxd9zxyjpsedOByNRj/XQzzGZQTCI7QNHp5XOFSoJOneglLP23+sEqJ7pNWJJ6S+c WkvQ== X-Gm-Message-State: AOAM530Z6LOIbAtg+hNrC162bC4LcsNAimfLwZOy7lhVKtaQf4suyfQA fV7Lafder4VF/hmz+WiavHphPtv4yoqseGXcJT1nUCyGiWyP1jDjsw71470Y6ORYeuHEURzalCe V9cqYRGS1j/hcQQ== X-Received: by 2002:a7b:cb98:: with SMTP id m24mr3469670wmi.133.1604071665886; Fri, 30 Oct 2020 08:27:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3Dcxvi3XzCBl1YGdtvla7Qmz6e78ESlq+XKDZyMg1El3isjuWJq/ymQKTrsJKa45YWs/nsA== X-Received: by 2002:a7b:cb98:: with SMTP id m24mr3469654wmi.133.1604071665744; Fri, 30 Oct 2020 08:27:45 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Laszlo Ersek , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-5.2] hw/smbios: Fix leaked fd in save_opt_one() error path Date: Fri, 30 Oct 2020 16:27:42 +0100 Message-Id: <20201030152742.1553968-1-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Fix the following Coverity issue (RESOURCE_LEAK): CID 1432879: Resource leak Handle variable fd going out of scope leaks the handle. Replace a close() call by qemu_close() since the handle is opened with qemu_open(). Fixes: bb99f4772f5 ("hw/smbios: support loading OEM strings values from a f= ile") Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Laszlo Ersek Reviewed-by: Stefano Garzarella --- hw/smbios/smbios.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index 8b30906e50a..6a3d39793bc 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -988,16 +988,18 @@ static int save_opt_one(void *opaque, if (ret < 0) { error_setg(errp, "Unable to read from %s: %s", value, strerror(errno)); + qemu_close(fd); return -1; } if (memchr(buf, '\0', ret)) { error_setg(errp, "NUL in OEM strings value in %s", value); + qemu_close(fd); return -1; } g_byte_array_append(data, (guint8 *)buf, ret); } =20 - close(fd); + qemu_close(fd); =20 *opt->dest =3D g_renew(char *, *opt->dest, (*opt->ndest) + 1); (*opt->dest)[*opt->ndest] =3D (char *)g_byte_array_free(data, FAL= SE); --=20 2.26.2