From patchwork Mon May 6 09:17:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 1931843 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Qcd/DEnU; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VXwqH3WDrz1xnT for ; Mon, 6 May 2024 19:20:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A7045384640C for ; Mon, 6 May 2024 09:20:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id ECA85384AB45 for ; Mon, 6 May 2024 09:18:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECA85384AB45 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ECA85384AB45 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714987084; cv=none; b=pPK+SX8/AVfT1fShrhBGvSBALxJMX6CPdFpzp6BUOaVAYKdlNVIFCNITwZcaOpaeSzhklAgOKYVXqpgZbq0TDyY7JwMOgp48Aac5uALscDOy7Y/M6ao9dKPWztTEXUglpR8hQYgmpLzsLGnBy49h4Wks3CgiKk/Vt3BrtF41cok= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714987084; c=relaxed/simple; bh=u8kpo1tsKMNEgla8tOL2Rdde0/BLGBCKJYVoONxBUKQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LgJ3dIsx0U3nYxy0il/XgSffx4ZK8hCdfz6KT2OqdqfPtp8xdhI5IghjIBXIDrdnoqmbYqjJeP9y7iW0jVmopfw7peYII0yZij/hW7kh0Lh0UR7t0WKZ7RdOqEg6kfBMm0u/bpvHtLNpeER+m9M7XMnfJnqPdKm4+OCKR6H3200= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-41b2119da94so10192995e9.0 for ; Mon, 06 May 2024 02:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1714987081; x=1715591881; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=aVkZ1AZEY+DCHDK/yuL3Gbg6vWTlGsVce4NBma+GnG8=; b=Qcd/DEnUepAtngWsjpIcrJOMWPcxYnBldRc/sk6sXEEs2f7mphZiGn/SBiIR1EP2Vo cz13eO9GoqOei06V2kuA0o5OC9OgDVzBTEu3wJLDxQBQUMDQK8BrKzV+L4UihYAWGSgX 2I7wWshqy9+/tAu2gxTWBy27lhx9JABh0YwBoXDgwlmp1/0RTPL9ztK3NI6YqhAVWUcZ kTPb2Gdl1d0v9SXclTDwlAaPgZhSw8oDG5epeJe5btfM4peHkHSRMGrvawWbjXDQQ5q5 s7C4WsLD+VLiQaqalF2GuBtleZ4UD8FoZlD18tQb3i9LQf/LIlWPRXuHzRRvWmQ/iAzp j1aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714987081; x=1715591881; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aVkZ1AZEY+DCHDK/yuL3Gbg6vWTlGsVce4NBma+GnG8=; b=SckYoKYEYX8IvGuMOc6w0TtrRXIBKV8ocBFW9CJOjaroXbOcWQ8yrp6Br484G6GQrH ggOzlquAOrPGRo/K/O4euXqHuSys8HIl4Ls3FI3phsr//cn3p9nyYapSQPZ0q+G8LdCy 6i2tWCLbX1B9mnuYai5iuo32lFU6X16BULbNevhX8Z3tgcctlwVet0H3+QuQrDpK5vI2 3oIADZE2+f/4c/AXwEH/jLp8gpUrr28elZxtOoaoWIEFyb6N/U/HBzu2WBJrRV3EoTUI 20AjKvvMpuLuHl9SKsp3EdlBhqgtfKc/aWE2+wRins729Ec5vFQe9qojsqfGnL3gZ53i GTkQ== X-Gm-Message-State: AOJu0YyY4O/jrEJ+uknJwyLmPosXBOFjzI5qBiKVtbQQA7YtXZgzGnIA vZttKFevan5ScrnJix9iF+a75K0tnixCAAF4N9K0BfeY9N4cbIbU6TV0xfI9/FAUep32GeCKoyM = X-Google-Smtp-Source: AGHT+IHxzax+RwXDrDGIpihFbDspnlRRD0B34zLzi3I+zVydmT0/zmscgq0JDTPgPrAFZ4ZdKJMDNA== X-Received: by 2002:a05:600c:5247:b0:418:5ed2:5aa6 with SMTP id fc7-20020a05600c524700b004185ed25aa6mr7766413wmb.31.1714987080781; Mon, 06 May 2024 02:18:00 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:9ea2:39d7:df74:396d]) by smtp.gmail.com with ESMTPSA id p20-20020a05600c469400b0041bc41287cesm15391716wmo.16.2024.05.06.02.18.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 02:18:00 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [COMMITTED] ada: Fix memory leak in 'Image Date: Mon, 6 May 2024 11:17:59 +0200 Message-ID: <20240506091759.1585137-1-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Bob Duff Fix memory leak in 'Image by managing the secondary stack in scopes that call the new Ada 2020 'Image, which calls 'Put_Image and then Get, which returns on the secondary stack. gcc/ada/ * exp_put_image.adb (Build_Image_Call): Call Set_Uses_Sec_Stack on the current scope. We don't do this at all call sites, because there are three; better to do it here. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_put_image.adb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb index c298163f36f..182497fb6e8 100644 --- a/gcc/ada/exp_put_image.adb +++ b/gcc/ada/exp_put_image.adb @@ -1290,6 +1290,14 @@ package body Exp_Put_Image is Actions := New_List (Sink_Decl, Put_Im, Result_Decl); end if; + -- To avoid leaks, we need to manage the secondary stack, because Get is + -- returning a String allocated thereon. It might be cleaner to let the + -- normal mechanisms for functions returning on the secondary stack call + -- Set_Uses_Sec_Stack, but this expansion of 'Image is happening too + -- late for that. + + Set_Uses_Sec_Stack (Current_Scope); + return Make_Expression_With_Actions (Loc, Actions => Actions, Expression => New_Occurrence_Of (Result_Entity, Loc));