| Message ID | 20260602084541.3829876-15-poulhies@adacore.com |
|---|---|
| State | Committed |
| Commit | fc0cd2781a254046eaa1bc930ed2ab2050ac9dea |
| Headers |
Return-Path: <gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 925BA4BA2E37 for <patchwork@sourceware.org>; Tue, 2 Jun 2026 08:51:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 925BA4BA2E37 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=FJ8Nby3v 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 8EA1B4BA2E2F for <gcc-patches@gcc.gnu.org>; Tue, 2 Jun 2026 08:46:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EA1B4BA2E2F 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 8EA1B4BA2E2F Authentication-Results: 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=1780389969; cv=none; b=H+XfTltBBIHyIvEcE38UR2CUM9dqTztLYCm5TlzJWxZ4vFFl3i4Qzxfx+wCTkuGFSCVBJ/S0SE/fcQ+v+32UkN7QQq+S7ZP2WAnsyGdGz2zOYt/glnN8mkdgl7TvfF4+VJqCPQB7jQLTgqG2mK1Z/LzPZIpFKdZ4UXVM1NKV58I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780389969; c=relaxed/simple; bh=WfHE8mgfxSHMQb7dmjPHxvTAlRDHdFU2dmub+mt7VPo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=An6KDn40VTh7YRK8DA8KbUXxykRTpv4xcWMlMxVm5dt8zQTOTF1buIDyDTpYVjXvnhZ99olDjMFHUsHfIZrgyV+geSZmfu3R7JtiBfLpCNykjrbPXF/mZRgQPZFIdbyweafGJuHfPpDqEhrdRdV8rN4HXjmaBKXAej35wWCsNMw= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=FJ8Nby3v DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EA1B4BA2E2F Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-49068493267so62486465e9.1 for <gcc-patches@gcc.gnu.org>; Tue, 02 Jun 2026 01:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1780389968; x=1780994768; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xbXFZ7TSXRoOD/iJZ3u8zsbph4KG5N8kEXjGwRmu+Ko=; b=FJ8Nby3vybApw4RNuBsfo29BYsnSPwGYROJIKuYs7wXFTEOSfohsDAd6KRrEaPczhj BnfzwJyVFWccZeuLS+l5mYkI7hdZdNHYVgaztaVC5W1iFxxqmxmwcysasrSWK+Iglvg+ 3V+Tb3Wfvg4HyCahXFkbPNooRgKybz0KYL3Iu2Agbb4Uc2+62AKb86HJ7PDtRBe0zu2U YMw9TlCRz51QkVUqt2rgj6X0pLShuBNMICOOZCViB/+aemrlE0xhYvuQSR3yM9DVsA5k eHz1A0xytazE4eCt4AmKIPspo46NCPYeC8XkoSD45oWeIQ1UN3sXliAP8lkZXAxZ+P64 ANJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780389968; x=1780994768; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xbXFZ7TSXRoOD/iJZ3u8zsbph4KG5N8kEXjGwRmu+Ko=; b=cVku0zRe1/YdhhVrtsThTPBbbSwI7VMMyskhoZ3Dr8Z7s5NOCZ2xYctdo9ZGvO5UDU PoIh9+em98bJAjuEzwDHD9v0P5/HiAShAMIKPGMxIDGlNDUT2pZOM08udVRbtjXEBiKK AjXRHqmFVaSZtHO69rOQI6r2+/PaAFDc+7MYr36d4BtGOJrHvHw45UlLSDO7j9WgnPiX 2uvysVWl6TJM2UwXsUzUIL19Xf1GYYYYAdZD7ihBEb7a+PYBBxlFxmFtXrqTt/V/enww AyXTUukhM0AQAA+oYX3PLMk0pEbT+IwiGrKEAENWAPdCVdjwK6/jyEQWW2z5GYtkpZvP P9ZQ== X-Gm-Message-State: AOJu0YwivfKUlyjDU71vK8zleuvdkA+S08P03oYkcg8NN5DJoD62RbLT CA2+CDcVK6qimBECiIAM4WrAiASmpVJ3YgFjZlzbX6Aeh0pBdF6PMSdzRlCqN9AeQnCTelnK8hV l2Hc= X-Gm-Gg: Acq92OHDyUuWkB4tjUxaNsq0xg+UfmPD6kpelhXh9prbivvwSvR4l7SunPg6wvF5eeP KXOdkzoreTRU10avFnqdiJH7ikCjVgemkrj7/VEHUy7L46yhjVLGO5vpaV2vszu6UdEaA62al6n km45uHjWOSDbE//EHAXUFRgFb5Hh/V1BACY/LDayis943oowLcgF264B+or+Ebq+jQjt4auRsCc T2YO/J1rhfSxLn57FiOBjF7QQwF1FWUOUiJh3p9+rv/uCg4SxwBOUAh1EchIWcQ4THWcLDu4hWK flL3WEt4kcqW8TIfbQk7geW0zqjPNf+ae8paui+SkXGKT2dLMieSxBYhqEgHGSNalXZDTPmQQj+ 0d3BD47S3CoBVaBz3TytUWpd5xL08AHm/vTP+vLFPDLWGhiBK/DZQ6v/kKGk+3XLs07ix0wrAxg 9TwOjEWfaDKU7snWbMYqWs+klhftiAwdsGEZPAOKE3W8TvuIFHhhTYAifhhkW5LdDUVdy2LQ3g8 3pmUntaRW57g6Eth+Dua3UtAPW7BOkFfDRPPy4Zug== X-Received: by 2002:a05:600c:4714:b0:490:a296:fdad with SMTP id 5b1f17b1804b1-490a296fe25mr239688335e9.24.1780389968557; Tue, 02 Jun 2026 01:46:08 -0700 (PDT) Received: from mecano.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490ab55d39csm33907625e9.35.2026.06.02.01.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:46:08 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= <poulhies@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Mathias Aparicio <aparicio@adacore.com> Subject: [COMMITTED 15/51] ada: Fix memory leak in __gnat_setenv Date: Tue, 2 Jun 2026 10:45:03 +0200 Message-ID: <20260602084541.3829876-15-poulhies@adacore.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260602084541.3829876-1-poulhies@adacore.com> References: <20260602084541.3829876-1-poulhies@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org |
| Series |
[COMMITTED,01/51] ada: Rename Private_Component function
|
|
Commit Message
Marc Poulhiès
June 2, 2026, 8:45 a.m. UTC
From: Mathias Aparicio <aparicio@adacore.com>
Before this patch, the code executed on Linux used `putenv`, which
requires a memory allocation. However, the memory was explicitly freed
only for Windows (`__MINGW32__`) and older VxWorks targets. Because
Linux fell into the allocation block but not the free block, there
was a memory leak.
To fix the leak, `__gnat_setenv` now calls `setenv` for Linux, doing
the same thing we were already doing for macOS.
Note that putting Linux in the Windows block is not a solution because,
on Linux, `putenv` uses the pointer directly and does not copy the
string. Therefore, if the memory were freed right away, there would be
a use-after-free.
To be careful, we do not use `setenv` everywhere else (except for old
VxWorks targets and Windows), because there might be problems with other
configurations if we do so.
gcc/ada/ChangeLog:
* env.c (__gnat_setenv): Add __linux__ preprocessor macro
directive to the setenv block.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/env.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/gcc/ada/env.c b/gcc/ada/env.c index 2931220f069..d37d2bc7a02 100644 --- a/gcc/ada/env.c +++ b/gcc/ada/env.c @@ -100,10 +100,11 @@ void __gnat_setenv (char *name, char *value) { #if (defined (__vxworks) && (defined (__RTP__) || _WRS_VXWORKS_MAJOR >= 7)) \ - || defined (__APPLE__) + || defined (__APPLE__) \ + || defined (__linux__) setenv (name, value, 1); -#else +#else /* Why don't we use setenv on all platforms where it's available??? */ size_t size = strlen (name) + strlen (value) + 2; char *expression;