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 D2AA53858C35 for ; Wed, 6 Dec 2023 14:39:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D2AA53858C35 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 D2AA53858C35 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=1701873590; cv=none; b=E8PyPbsWRB/tx4SOj2jzZhzoW3ktoc/lTHqmHqztmFEYuwElJus3SaHr4o3NEdGxNr+TyFGhsGh+9qRBtEsY1ZGnr9PzLmqddg4UFwgB7aCvCCY7y720NZ2aD9Yj9zq/h6VxQgFFITSVoGgYrhDO3frlwo3RV4Opn5JlU+VfToA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701873590; c=relaxed/simple; bh=ovxKyTWQkxCV/tTpHSC6r8dWEoEHVIo76uy5uITA3V8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=fVNCwey/AQyiPzESCtie87YnMhnc0rpRRg0TGpCEV53Uv+NjfxAhOXGWB7RkWKvxio0TDKdjbxkWXEsUB8frG99lskScWGlu/UIZLRbui8j+HYMdMyqXGAWN11ie2tuSkP7LaW4IDY+k4aU1SmOYObO8xfoCDkovFdV9YWmHzxk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701873588; 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=agdx7wJmdYTN1SaemC1YOAnyaPHqB4YsK5Uyq2k39VQ=; b=DnCMz+vbB0Ci+7Wn5GyVZkmXRwiGPdDzZMUafbA9dZYMKMs7F73cTNoHcU83pTsfe/6OHv RxtVQVR7mAst5P8tERBK/L+zz/5LDj35JhClXFKZoPqpy/iBogXF/0LIgx2lNRgB55CDcZ c1Wavc8t+QICFc5kKPyKW+WVcgYqx7w= 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-269-AN12qr0UMkaLhkHKV_0_tA-1; Wed, 06 Dec 2023 09:39:44 -0500 X-MC-Unique: AN12qr0UMkaLhkHKV_0_tA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 25DBC870823; Wed, 6 Dec 2023 14:39:44 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D63E6111E400; Wed, 6 Dec 2023 14:39:43 +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 3B6Edf5f1609781 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 15:39:41 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B6EdeeF1609780; Wed, 6 Dec 2023 15:39:40 +0100 Date: Wed, 6 Dec 2023 15:39:40 +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.3 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 Wed, Dec 06, 2023 at 02:29:25PM +0000, Costas Argyris wrote: > Attached a new patch with these changes. > > On Mon, 4 Dec 2023 at 12:15, Jonathan Wakely wrote: > > > On Sat, 2 Dec 2023 at 21:24, Costas Argyris wrote: > > > > > > Use std::vector instead of malloc'd pointer > > > to get automatic freeing of memory. > > > > You can't include there. Instead you need to define > > INCLUDE_VECTOR before "system.h" > > > > Shouldn't you be using resize, not reserve? Otherwise mdswitches[i] is > > undefined. Any reason not to use vec.h instead? I especially don't like the fact that with a global std::vector var; it means runtime __cxa_atexit for the var the destruction, which it really doesn't need on exit. We really don't need to free the memory at exit time, that is just wasted cycles, all we need is that it is freed before the pointer or vector is cleared. Jakub