From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id E228C3858297 for ; Thu, 7 Dec 2023 15:16:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E228C3858297 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E228C3858297 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::531 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701962212; cv=none; b=pkKeKTLqPdtxGremtBBrWQqETr2Nop1PODlVVl8g4sZowOSckIa4BDK+8rukZwEtASsBvbA7ev+uLwMBCyskEVzNeJos7vxm+ZefoRixBl3ziZpjgUsd3rzBWgQzMkOAByPR3sEkSoR+tqTTrZ0mplFJf+JjYs6HVtAcp4nHUZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701962212; c=relaxed/simple; bh=HIf00i7ChGzeYSk2iPzyridR8KxXoCMXWTCOUrhK0k0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=JLg5X+MnMvTGLJqs5hVboMnQaXFoVZcXaPclVeqRaRdzNN69P5WdNVinwCm00ElnROkWBn8bv4CvrJKPFsltrou8AghtRd3ODpUiIqrViLeS5wWsbA/a0ScMpsONA3L49ZbCJrSPgIulOhqLJmOXjLDd4/9XptCeHkXlHiMwq6s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-54ca339ae7aso1559433a12.3 for ; Thu, 07 Dec 2023 07:16:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701962200; x=1702567000; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=1ll7KcSGyUiowu4alDwHs116+Wr2NX8voFFK6ah7Qsk=; b=LzxrxWJFV2MELyFiiSi+Ni3n2r0uU/jtFJpLEJXq7SYgtRRYjfftXggluJoH9JeUH4 nW81wiRRwIprzRNyZVz7OwvkQszA2rxnvAgUTtb6Pj7lSrmPCAhJtZU3BYKZr6jfnG7u 0ov7K1QkoeTNG40T2A57Yy0/Y7QxqqQkn9oehaMvlTKapUPJ5lF7EXQ9oHRqI4qNVWtj VTKl1YyXRLwGuyQrP72LFwDou/SKzrFDrJ5hjpttxdGgfXu+bbEPS5t4YpKdUBW4Z6n6 yR7/9hGq9OoliGGKV/7ga9F2uI1fcDBmtvmhDC9E2IqY7NABLQlBpjFVuNfT+YhJnkBB m9kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701962200; x=1702567000; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1ll7KcSGyUiowu4alDwHs116+Wr2NX8voFFK6ah7Qsk=; b=a5f45le5G42RvlWlEp2lyITlN6DfsTnG6T6vpb8oD8yi/JugM1ULdXC7DYdIkiDCd9 /+1XXjTIruWnF38igabmi4fBmedk3UMG7/Q+SU0r91YKJYcdAfqT8aqsnY4HR93qgFwg Y4MxI6B3ceGs4u3eBhDgj15b/5TdwmC4kDBhswQiy2Z12fWNJsNZgywj1IQcmCWF7jsp lG9tiOfPawez++rQSJj8mKKPXWdn5F9gHji0N2mGU9ZzqpjyIZrtsYgJUUUp1+OXthgh tTQc/sq/+jM8kJE5Gd5+xk5PpBGuJGm2wbN3oeR8G3y2kola/dwRBAH6A8dPpTIy7f3y jZeA== X-Gm-Message-State: AOJu0Ywks4dP0aZzF7NPm0UBivB8BwXDLZ57LN/yyVx7rjKRJ9zbaqxW 4B4YouGdkpmesHzB3kKEc8GKdAjutdAJpKbcZ+plToF4a0o= X-Google-Smtp-Source: AGHT+IE1x2fJhCz0TkR4wxB4l7iLKQwJEXJkOppycFDZMFuYYdNnCphtwntLTaPjQbvd9qQ5rTkXDp6geV2140yAW5U= X-Received: by 2002:a50:c2d1:0:b0:54c:fdb6:5c4c with SMTP id u17-20020a50c2d1000000b0054cfdb65c4cmr2030168edf.12.1701962200180; Thu, 07 Dec 2023 07:16:40 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Costas Argyris Date: Thu, 7 Dec 2023 15:16:29 +0000 Message-ID: Subject: Re: [PATCH] driver: Fix memory leak. To: Jakub Jelinek Cc: Jonathan Wakely , gcc-patches@gcc.gnu.org Content-Type: multipart/alternative; boundary="0000000000005cebe7060becf474" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: --0000000000005cebe7060becf474 Content-Type: text/plain; charset="UTF-8" > Still reachable memory at exit e.g. from valgrind is not a bug. Indeed, this is coming from a valgrind report here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93019 where it was noted that the driver memory leaks could be problematic for JIT. So, since using std::vector did reduce the valgrind records by one (I only targeted a single variable to begin with) I took that as a good sign. Regarding adding a call to XDELETE (mdswitches), yes, that would help in the case where driver::finalize () is actually called, which I think is for JIT. I was trying to take care of the case where it doesn't get called as well, but from what you say I take it that this case is not of interest. On Thu, 7 Dec 2023 at 14:42, Jakub Jelinek wrote: > 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 > > --0000000000005cebe7060becf474--