From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id 7408E385C411 for ; Thu, 7 Dec 2023 16:01:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7408E385C411 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 7408E385C411 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701964886; cv=none; b=Gn4VNgGfCFLPbbUizegWRwrOFWSyQMp0KkDx6Zj6afx8IHlmcFZV2Ic25QwvLTxR1ICf/WZCOSfsSSK09Ogct0twQFO0kiqozPrEmPImN0xQHLY91Nd/4XMeigJ3xZjVeF1O22YHZmcrUCPmB93lqRedvkssGLDACU7uVz8gCSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701964886; c=relaxed/simple; bh=x9XHjf3M5V7yypF2h7oyLG2ZdOTEvpcDkzmlycJJ84I=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=dlaAJXR3+tZ2uDQ6M5dDgI9NF6ywEw1dMzD7uRcEDpV7UWRAt3bYSg6CBR4EP9KhZ0kfz7mpYagz+CCjjcxR7aUBpE1JNEYkEbBxgo/RMkH9VxPMFWh5VB3t2c1bfIgGeGBnY5IjEsi6rvDGmx6N7t/7dx4JjbK5msL569KMaUU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-50be03cc8a3so1177339e87.1 for ; Thu, 07 Dec 2023 08:01:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701964883; x=1702569683; 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=eOlQYv0nGXHYzg1vkRfVxbg3ZeraIAPL+9xa8OocjT0=; b=UN4OqdgNgVUVUlmsHQGWY8Od3jsDiynXLoiwisRVmMo21KZjsN+qSkhnNABTJ9L7pO CaBSmXSDHhwEPiqeTCFPc+LgrbRAUghJYc3OTM7HZjie3UK7QJ2TGzGcd+4V6EyZDFMV imY0KQK66OIhwvFTeuRvUxYtLFvmb8mRaami+TcmGC3T8eXNBcp1X5f0VSv/i/dfafFt 3dtadO9MusA32+/FrKluCoMItmgQAs5RY13G+ESgbWkJcVohs/PaIo5ziCHTDyAaUx1z oK3Urpx4B9khZh660476j55uIxyOsLIpfSWBo6UM0C9kt32GFoYVcsyNZNZsfZG8X1i7 CZ5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701964883; x=1702569683; 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=eOlQYv0nGXHYzg1vkRfVxbg3ZeraIAPL+9xa8OocjT0=; b=a94/OWAJNIzRjGnYaIIw9w3MDYEybrRIBVr6tjEhfObszMKLtaUX2/pHkEbhAeaqp6 crjbHSXzLK3bH0eEWe+TQeQb5NfWR70d8uu78H58mX6VgZO/Qhq4rXEsnih8PH/kpWpV RQmd+NwHxfGur/HC1KqZ2Y+5ka9wrsyL9xKpVQD3aeEQicfHRfXeQolXwnUaNYIKIgvM 3iWqe+Gcx+tj8c7s/MyPAGsNn3RMZhJ5dSMHdliNVJiDaNcnvsNN4NJsQLR5Y+u6D/WD 4dGmRWbrg2Hq9bnDcumaAmdZeLNbt1tnnFUW5lh3yIQtTL/W6jTmlgnCZ/3kHN/VWAFD J1bg== X-Gm-Message-State: AOJu0YyPvlZgbnz5kw4meL9HfYKNPUP+n+qPhHjZ1YefZy7IMlJe1HnV QAOGOjBmue2dpfcaYrI++lib1vXdC9lsBrZ8Q3M= X-Google-Smtp-Source: AGHT+IEr0tpbKiRSt2ncSGegXWyYTLbpybU+/tlK9rWhqChfyOLqJqcOkCe0tCmIyfB2k7SGstRy6RpDlAX7l48/TcI= X-Received: by 2002:ac2:5de7:0:b0:50b:fbc2:f70c with SMTP id z7-20020ac25de7000000b0050bfbc2f70cmr2010325lfq.114.1701964882460; Thu, 07 Dec 2023 08:01:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Costas Argyris Date: Thu, 7 Dec 2023 16:01:11 +0000 Message-ID: Subject: Re: [PATCH] driver: Fix memory leak. To: Jakub Jelinek Cc: Jonathan Wakely , gcc-patches@gcc.gnu.org Content-Type: multipart/mixed; boundary="0000000000003dfe01060bed944a" X-Spam-Status: No, score=-1.1 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: --0000000000003dfe01060bed944a Content-Type: multipart/alternative; boundary="0000000000003dfe00060bed9448" --0000000000003dfe00060bed9448 Content-Type: text/plain; charset="UTF-8" Thanks for all the explanations. In that case I restrict this patch to just freeing the buffer from within driver::finalize only (I think it should be XDELETEVEC instead of XDELETE, no?). On Thu, 7 Dec 2023 at 15:42, Jakub Jelinek wrote: > On Thu, Dec 07, 2023 at 03:16:29PM +0000, Costas Argyris wrote: > > > 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. > > In the invoke_embedded_driver JIT case yes, that calls driver::finalize (), > which is why it should be freed before clearing the pointer in there (as > then it is a real leak). > > > 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. > > That is wasted compile time on a non-issue. > > If you see a JIT issue with definitely lost records, that is something > that obviously should be fixed (but even in that area I think we've been a > little bit lazy in the option handling). > The most important is that the actual compiler binaries (cc1, cc1plus, ...) > don't leak memory (in the definitely lost kind) like crazy, we have > --enable-checking=valgrind > for that purpose, where the driver runs cc1/cc1plus etc. under valgrind, > but this is very expensive and slow, so usually it is run once during a > cycle (if at all), on a fast machine could take even in non-bootstrap mode > a weekend to go through the whole testsuite, then one can look at the > leaks. > > Jakub > > --0000000000003dfe00060bed9448-- --0000000000003dfe01060bed944a Content-Type: application/octet-stream; name="0001-driver-Fix-memory-leak-in-driver-finalize.patch" Content-Disposition: attachment; filename="0001-driver-Fix-memory-leak-in-driver-finalize.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lpvdvcq10 RnJvbSAxM2Y2Y2U1YzE2NGYxZjBmZGVkMjVmMDFiMWQzOGY5MGIzNTRmZTEz IE1vbiBTZXAgMTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBDb3N0YXMgQXJneXJp cyA8Y29zdGFzLmFyZ3lyaXNAZ21haWwuY29tPgpEYXRlOiBUaHUsIDcgRGVj IDIwMjMgMTU6NTI6NTEgKzAwMDAKU3ViamVjdDogW1BBVENIXSBkcml2ZXI6 IEZpeCBtZW1vcnkgbGVhayBpbiBkcml2ZXI6OmZpbmFsaXplICgpCgpGcmVl IGJ1ZmZlciBiZWZvcmUgc2V0dGluZyB0aGUgcG9pbnRlciB0byBOVUxMLgoK U2lnbmVkLW9mZi1ieTogQ29zdGFzIEFyZ3lyaXMgPGNvc3Rhcy5hcmd5cmlz QGdtYWlsLmNvbT4KLS0tCiBnY2MvZ2NjLmNjIHwgMSArCiAxIGZpbGUgY2hh bmdlZCwgMSBpbnNlcnRpb24oKykKCmRpZmYgLS1naXQgYS9nY2MvZ2NjLmNj IGIvZ2NjL2djYy5jYwppbmRleCA5ZjIxYWQ5NDUzZS4uYmY0YTAyZjc2ZTcg MTAwNjQ0Ci0tLSBhL2djYy9nY2MuY2MKKysrIGIvZ2NjL2djYy5jYwpAQCAt MTEzNjYsNiArMTEzNjYsNyBAQCBkcml2ZXI6OmZpbmFsaXplICgpCiAgIGlu cHV0X2Zyb21fcGlwZSA9IDA7CiAgIHN1ZmZpeF9zdWJzdCA9IE5VTEw7CiAK KyAgWERFTEVURVZFQyAobWRzd2l0Y2hlcyk7CiAgIG1kc3dpdGNoZXMgPSBO VUxMOwogICBuX21kc3dpdGNoZXMgPSAwOwogCi0tIAoyLjMwLjIKCg== --0000000000003dfe01060bed944a--