From nobody Wed May 15 13:44:16 2024 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=1618247223; cv=none; d=zohomail.com; s=zohoarc; b=YwZzc7OvTAzEw3J423+MSDvW/PXxxUi9b8kGyY6NK3I8303q+65/rXU78QSGeG83DW2GMu1tZofz9uzzjqpBrFoXGhUeeXfILc9tOX5+4veOpP9LUqxJLRytCZFYg7eDVrBmp6LSsCnAHNjBAcn9Axe0MIfI3s+RO0wBLsjBrf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618247223; 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; bh=1fB3s6acNZaWEL9CR0kUeQrmSUdbUvbWIwVGGqKlqG8=; b=Stb7R3Yz509b5am2zfmlUxSJ11AhNu36dyTpbTgW8RiVIJtDpauueTkU9Judz6hntgLiPt4NxK2zh0wsN8ybMGn1JZSWxu5EO5mjlfKm13iBDUv+k+0O8dTcLJTaSQpNGreFm0OlNn+yLjT/RbaZV31UDjoSllM/b0p8Ks2hAQc= 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 1618247223725587.8827708398074; Mon, 12 Apr 2021 10:07:03 -0700 (PDT) Received: from localhost ([::1]:46292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lW01d-0003b9-UW for importer@patchew.org; Mon, 12 Apr 2021 13:07:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVzxp-0002Kj-CV for qemu-devel@nongnu.org; Mon, 12 Apr 2021 13:03:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVzxm-0006Fg-Ag for qemu-devel@nongnu.org; Mon, 12 Apr 2021 13:03:04 -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-333-miJ135L3Nc-uZIU3JmAH5Q-1; Mon, 12 Apr 2021 13:02:59 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8D6A1E586; Mon, 12 Apr 2021 17:02:57 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-252.ams2.redhat.com [10.36.113.252]) by smtp.corp.redhat.com (Postfix) with ESMTP id A19BB60BD8; Mon, 12 Apr 2021 17:02:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618246980; 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=1fB3s6acNZaWEL9CR0kUeQrmSUdbUvbWIwVGGqKlqG8=; b=M3eutFecnCEUipO/GKXeHozcYyXQFHnuDtdpvNPE7IKorLREzUhDsZiC3qiFWnr55aGYOJ duCFKAW8PAn8CQRDAnw3HQjTpvH5NRs5CN9ln8Zf417hhMGdI/dHvWA7ykmFGrvU3z8MOW apTTpvuZv1fdVkBnKnwJVE3ZrwYF2uE= X-MC-Unique: miJ135L3Nc-uZIU3JmAH5Q-1 From: Stefano Garzarella To: qemu-devel@nongnu.org Subject: [PATCH] cutils: fix memory leak in get_relocated_path() Date: Mon, 12 Apr 2021 19:02:55 +0200 Message-Id: <20210412170255.231406-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=sgarzare@redhat.com 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=216.205.24.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" get_relocated_path() allocates a GString object and returns the character data (C string) to the caller without freeing the memory allocated for that object as reported by valgrind: 24 bytes in 1 blocks are definitely lost in loss record 2,805 of 6,532 at 0x4839809: malloc (vg_replace_malloc.c:307) by 0x55AABB8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.8) by 0x55C2481: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.6600.8) by 0x55C4827: g_string_sized_new (in /usr/lib64/libglib-2.0.so.0.6600.= 8) by 0x55C4CEA: g_string_new (in /usr/lib64/libglib-2.0.so.0.6600.8) by 0x906314: get_relocated_path (cutils.c:1036) by 0x6E1F77: qemu_read_default_config_file (vl.c:2122) by 0x6E1F77: qemu_init (vl.c:2687) by 0x3E3AF8: main (main.c:49) Let's use g_string_free(gstring, false) to free only the GString object and transfer the ownership of the character data to the caller. Fixes: f4f5ed2cbd ("cutils: introduce get_relocated_path") Signed-off-by: Stefano Garzarella Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- util/cutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/cutils.c b/util/cutils.c index ee908486da..c9b91e7535 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -1055,5 +1055,5 @@ char *get_relocated_path(const char *dir) assert(G_IS_DIR_SEPARATOR(dir[-1])); g_string_append(result, dir - 1); } - return result->str; + return g_string_free(result, false); } --=20 2.30.2