From nobody Mon Feb 9 23:16:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594742772; cv=none; d=zohomail.com; s=zohoarc; b=T2Fb9uZalaQvWaEzlF7g+Xu1N/gGT7LPvbMoghGBRhdnhWCdP/lSBjKRETdEyjUAFDFBB1QM7mtsTt4SijskYOmIyS+USQnxMeROsNpAt+WorMtSNx7lpTwvPAFV/m9UpATBhWd+XB/fzCeF6xxvFfzl5nuQPOyKqMQhATD9+os= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594742772; h=Content-Type:Content-Transfer-Encoding:Cc: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=ZyHJr/bBDTg6+0dit92IOQ9uBFEdiYfGfe+lP+xf4C8=; b=hhljTtJcyBCPoJyP6RAjpgnr3GmaTvzxGWjFP3D0AlK4XQhlq2WiFpjhtSB3ARhPTWqcN8zHijXH3/5YeAQQM0NYv3CPoPj/RczcqO7iNEVWEAzbcEPXUTvx91pMNbqKFJvyEhnYA0MvMDznVoT0LDAANyTk+jnkYnQE9+hTKRE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1594742772065426.9447500556678; Tue, 14 Jul 2020 09:06:12 -0700 (PDT) Received: from localhost ([::1]:40728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jvNRZ-0005EC-SZ for importer@patchew.org; Tue, 14 Jul 2020 12:06:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvNNm-0000Kt-IY for qemu-devel@nongnu.org; Tue, 14 Jul 2020 12:02:14 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24391 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jvNNh-00080n-1h for qemu-devel@nongnu.org; Tue, 14 Jul 2020 12:02:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-212-VubIWJApNAWQnz-8TZVV0A-1; Tue, 14 Jul 2020 12:02:06 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E3C0B800597; Tue, 14 Jul 2020 16:02:04 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A3FBC5C1B2; Tue, 14 Jul 2020 16:02:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2EACD17741CA; Tue, 14 Jul 2020 18:02:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594742527; 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: in-reply-to:in-reply-to:references:references; bh=ZyHJr/bBDTg6+0dit92IOQ9uBFEdiYfGfe+lP+xf4C8=; b=BK/p66dP1wif58kbh/7dfAREHHl/78+wh+oZI7UzZz7rwuCAOpEONAkVUE8DcuhYP4RKll heTYtYpIojUZG1TuPXkTPX3JjrW+xiRK60B5jmN2zuKu1/LmAgjSOgz5ZACyYcKLzYqPa7 7HtF9w4CkphOfOXGOxcJI7ZVtNDBnOs= X-MC-Unique: VubIWJApNAWQnz-8TZVV0A-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH for-5.1 2/5] qom: Plug memory leak in "info qom-tree" Date: Tue, 14 Jul 2020 18:01:59 +0200 Message-Id: <20200714160202.3121879-3-armbru@redhat.com> In-Reply-To: <20200714160202.3121879-1-armbru@redhat.com> References: <20200714160202.3121879-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=205.139.110.120; envelope-from=armbru@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/14 01:42:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: lvivier@redhat.com, thuth@redhat.com, berrange@redhat.com, ehabkost@redhat.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Commit e8c9e65816 "qom: Make "info qom-tree" show children sorted" created a memory leak, because I didn't realize object_get_canonical_path_component()'s value needs to be freed. Reproducer: $ qemu-system-x86_64 -nodefaults -display none -S -monitor stdio QEMU 5.0.50 monitor - type 'help' for more information (qemu) info qom-tree This leaks some 4500 path components, 12-13 characters on average, i.e. roughly 100kBytes depending on the allocator. A couple of hundred "info qom-tree" here, a couple of hundred there, and soon enough we're talking about real memory. Plug the leak. Fixes: e8c9e65816f5dbfe18ad3b2be938d0d8192d459a Signed-off-by: Markus Armbruster Reviewed-by: Li Qiang Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Thomas Huth --- qom/qom-hmp-cmds.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c index 9ed8bb1c9f..aaacadacca 100644 --- a/qom/qom-hmp-cmds.c +++ b/qom/qom-hmp-cmds.c @@ -96,8 +96,10 @@ static void print_qom_composition(Monitor *mon, Object *= obj, int indent); =20 static int qom_composition_compare(const void *a, const void *b, void *ign= ore) { - return g_strcmp0(a ? object_get_canonical_path_component(a) : NULL, - b ? object_get_canonical_path_component(b) : NULL); + g_autofree char *ac =3D object_get_canonical_path_component(a); + g_autofree char *bc =3D object_get_canonical_path_component(b); + + return g_strcmp0(ac, bc); } =20 static int insert_qom_composition_child(Object *obj, void *opaque) --=20 2.26.2