From nobody Mon Apr 29 04:55:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@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 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1667401040; cv=none; d=zohomail.com; s=zohoarc; b=d/1njcOqufswSQTUICSsIbUW3NzpUWqMA5y7E2v/QeIfYu/dwtFLeahyN08ixGoeFojX1zy9vcVoXxrrzZ1FUpPnNk1rA962IkXrezav8qwkylDm3JnE/tVGiLfrddgAUh55M5gN/xswuha0xLGq3JAYaBn3D/dMgshu/Nkm55c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667401040; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=mDMPz3kGDR83mSfJzP9C7l8VVTd6OdA/IhCZhRqv07U=; b=ZhoVsE8lPSdJQ2x8tok+jmMTW58ge4xGgwOqwPoK8GegXSQVAYrAczButMlTdsRWgdXSJ4nmBssVDW0ZcjchbVSFcBlnOaOsosmhFyJVrHEhoI0GK6ahe5Nhsxa8FrSJj6jbplfvkuq6uONhZnCGGVeRwJD7DaOiC4NGYyiriUA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1667401040282391.210878647714; Wed, 2 Nov 2022 07:57:20 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-116-9Fzkn3J2PBO845k-tRfliQ-1; Wed, 02 Nov 2022 10:57:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7614D85A583; Wed, 2 Nov 2022 14:57:08 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1343840C2065; Wed, 2 Nov 2022 14:57:07 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 825751946597; Wed, 2 Nov 2022 14:57:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E04C31946594 for ; Wed, 2 Nov 2022 14:57:04 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A6D52141511F; Wed, 2 Nov 2022 14:57:04 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.227]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82A80140EBF5 for ; Wed, 2 Nov 2022 14:57:04 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id A20F8243015; Wed, 2 Nov 2022 15:57:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667401038; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=mDMPz3kGDR83mSfJzP9C7l8VVTd6OdA/IhCZhRqv07U=; b=CjLY1KYNvzpx9GumcP5nwBme+5l5UhYKjJhUHahsO1F//0R0K7+Tb2x873S8tcnPop9B6O UUAaSEHaywH6Ee/q9mAHnhMEkaE127FPaTn32dBsRoADfaZW8YvTl/qbgqQENAxz49Qcx8 QA8ecU4IuxVb9CBEhoLERKfAdiy8J+M= X-MC-Unique: 9Fzkn3J2PBO845k-tRfliQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH] qemu: Avoid memory leak in qemuMonitorJSONExtractQueryStatsSchema Date: Wed, 2 Nov 2022 15:56:50 +0100 Message-Id: <273819aeab88b7e7de6c0ddbf7ba2c5005381fa7.1667401010.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1667401040866100001 Content-Type: text/plain; charset="utf-8" In a rare case when virHashAddEntry fails we would just leak the structure we wanted to add to the hash table. Fixes: e89acdbc3bbada2f3c1a591278bc975ddee2d5a9 Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 2bd159bc98..8a3421a6fc 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -8596,7 +8596,7 @@ qemuMonitorJSONExtractQueryStatsSchema(virJSONValue *= json) virJSONValue *stat =3D virJSONValueArrayGet(stats, j); const char *name =3D NULL; const char *tmp =3D NULL; - qemuMonitorQueryStatsSchemaData *data =3D NULL; + g_autofree qemuMonitorQueryStatsSchemaData *data =3D NULL; int type =3D -1; int unit =3D -1; =20 @@ -8632,7 +8632,9 @@ qemuMonitorJSONExtractQueryStatsSchema(virJSONValue *= json) virJSONValueObjectGetNumberUint(stat, "bucket-size", &data= ->bucket_size) < 0) data->bucket_size =3D 0; =20 - virHashAddEntry(schema, name, data); + if (virHashAddEntry(schema, name, data) < 0) + return NULL; + data =3D NULL; } } =20 --=20 2.38.1