From patchwork Mon Apr 26 22:30:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 12224243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00, DATE_IN_FUTURE_06_12,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17994C433B4 for ; Mon, 26 Apr 2021 13:10:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 854FE61107 for ; Mon, 26 Apr 2021 13:10:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 854FE61107 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:34106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lb10U-000050-Ce for qemu-devel@archiver.kernel.org; Mon, 26 Apr 2021 09:10:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1laulF-0004va-6b; Mon, 26 Apr 2021 02:30:28 -0400 Received: from mga07.intel.com ([134.134.136.100]:63423) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1laulB-0007xK-6Q; Mon, 26 Apr 2021 02:30:24 -0400 IronPort-SDR: 0VQnWplUhKdcBxraKGIz+dc89vL8s7r9Krgs9GRwjyQXdxqLugkaALEg2lMnR+ynKRLxFg5p18 ENEu4JxoZncw== X-IronPort-AV: E=McAfee;i="6200,9189,9965"; a="260240567" X-IronPort-AV: E=Sophos;i="5.82,251,1613462400"; d="scan'208";a="260240567" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2021 23:30:06 -0700 IronPort-SDR: AkVlfQ4N4YI3SAok1heT26gTzJ9I0Q1ZPNjLzbTtvrLmq96LDme3WI3tSInu0yxB4Rm93tA0Fv cuPHhWETssGA== X-IronPort-AV: E=Sophos;i="5.82,251,1613462400"; d="scan'208";a="429264602" Received: from duan-optiplex-7080.bj.intel.com ([10.238.156.114]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2021 23:30:05 -0700 From: Zhenzhong Duan To: qemu-devel@nongnu.org Subject: [PATCH] cutils: Fix memleak in get_relocated_path() Date: Tue, 27 Apr 2021 06:30:42 +0800 Message-Id: <20210426223042.119554-1-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: pass client-ip=134.134.136.100; envelope-from=zhenzhong.duan@intel.com; helo=mga07.intel.com X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DATE_IN_FUTURE_12_24=3.199, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 26 Apr 2021 09:08:51 -0400 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: qemu-trivial@nongnu.org, pbonzini@redhat.com, Zhenzhong Duan Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Valgrind complains definitely loss in get_relocated_path(), because GString is leaked in get_relocated_path() when returning with gchar *. Use g_string_free(, false) to free GString while preserving gchar *. Signed-off-by: Zhenzhong Duan --- util/cutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/cutils.c b/util/cutils.c index ee908486da..f58c2157d2 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); }