From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0053B3858282 for ; Thu, 7 Dec 2023 14:42:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0053B3858282 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0053B3858282 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701960135; cv=none; b=XGHB9S6Sk0wrTS4mJkge/8oV6DTQBwRKAKx7vOcC36eAObYnEl25D30RoXmuFl/qSpwCN4HvVhwbp7G+OSNxqZQih0Qws0DkXTeNDRiueNJLAzi7CI9w6zWSHlYjYndwZc3rrSKh+h0hcFP1540Xuwytl8drTg/X3Nq7BjedIhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701960135; c=relaxed/simple; bh=51EB2rDJB1v3BBfRVjcYTZcRdD8c+CgXnAhnLVhE+Lw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=V5jJqWbLccyNoyLnSgRrWKLtdZG15PHYTqpx79WKk1KVndTuMar8LgthM89Q+oN5bToGJ9niJcNol4xqhd8cBPcwgAxf4XYs4BhdN9VbVrj9WT3RfJygDMwuvl/zN+COM5jStq7eiNbMm/6rKo6WtLUaKJVtHFY9o8F6x/graMg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701960133; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=tLw6C/2TpEnWB7BHasYQ1mZOUh1/R1H/2eUJ83/rviU=; b=CCpL5BxIEJr9iuYA+F9h8b95mRWU7tdxhrwQtlyxPVxAh45ukHUUxshvWPAqtVHfrJtECB CSYL6vNdTryNZ4y+NVzRulK5des97sxW3m5ywclMgm4Ro/B4n7jXPPnsMqHRgXLdW9vWea 1vTTTkdT1frpA+WXaxUBeBLujAjNe78= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-527-QXWwV5TnOKGxudRaYInoLw-1; Thu, 07 Dec 2023 09:42:11 -0500 X-MC-Unique: QXWwV5TnOKGxudRaYInoLw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A273D862DE5; Thu, 7 Dec 2023 14:42:10 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 63FB2492BC6; Thu, 7 Dec 2023 14:42:10 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3B7Eg79U166405 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 7 Dec 2023 15:42:08 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B7Eg7I2166404; Thu, 7 Dec 2023 15:42:07 +0100 Date: Thu, 7 Dec 2023 15:42:07 +0100 From: Jakub Jelinek To: Costas Argyris Cc: Jonathan Wakely , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] driver: Fix memory leak. Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Dec 07, 2023 at 02:28:18PM +0000, Costas Argyris wrote: > Would that be something like this? Yes. Or perhaps even easier just change --- gcc/gcc.cc.jj 2023-12-07 08:31:59.970849379 +0100 +++ gcc/gcc.cc 2023-12-07 15:33:46.616886894 +0100 @@ -11368,6 +11368,7 @@ driver::finalize () input_from_pipe = 0; suffix_subst = NULL; + XDELETE (mdswitches); mdswitches = NULL; n_mdswitches = 0; > Although it didn't fix the leak, which was the entire point of this > exercise. > > Maybe because driver::finalize () is not getting called so the call to > mdswitches.release () doesn't really happen, which was the reason > I went with std::vector in the first place because it takes care of itself. In that case you are fixing a non-issue. exit frees all allocated memory, no need to do it explicitly and waste compile time cycles on it. Leak is when some memory is allocated and pointer to it lost, that is not the case here. Still reachable memory at exit e.g. from valgrind is not a bug. E.g. glibc in order to make fewer still reachable memory reports exports a __libc_freeres function which valgrind and other memory allocation debuggers can call on exit to free extra memory, something that isn't really needed to waste time on normally. But I'm not sure if there is some way for an application to provide such functions as well. Jakub