From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2b.google.com (mail-vs1-xe2b.google.com [IPv6:2607:f8b0:4864:20::e2b]) by sourceware.org (Postfix) with ESMTPS id 9B08B3858D28 for ; Tue, 12 Apr 2022 20:57:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B08B3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vs1-xe2b.google.com with SMTP id e11so17421321vso.7 for ; Tue, 12 Apr 2022 13:57:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LfcvPuoXon27b4XuEhq6OHBH/nGsnhezfMGw+mKq20g=; b=OQwKwBd7epyzRNTXapVSHFoidGcAe35XM4QiLPj3VEexOgCK7y1Jdd8WMVMd6ruoqo Y1DCLz8puAfjCyR+iqIMrVEbpJeMENrqtd+YFKRoHaXaQJ63hV1w5UpsZiib9LU0Vnc3 a2lvFUdwAsjrHK3BTHZKOe9s6aLLAOKPJSneWTExFwsQcnlXXB70vCrFO2jRk7ErPtiE aN81zRIl0DkKI/Hl3X6bv/QAcAUJnFYO//7NLLgiWPnsB9ArBwByyGajo5TR17Tq+9kF Q6VvXMeCLxZekotpoaM5X5XKdztcltMMI6tUbAu9P+3YTTazdzQ/bSbXpC9bo29UPaXE eyxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LfcvPuoXon27b4XuEhq6OHBH/nGsnhezfMGw+mKq20g=; b=Mijae0/66+C1e0wrhFMV3VhUyuiD/N8i4HRth2h3sOWLASaw+PUEt/Xl3Lr5ZOVBk/ GBfaDVC9nrUSW4mE1A+gij37BKFFBJjFm92397DhDzitL4sV9MazSzdv4zKKm4P/WZpB zUAMFkzycR+AzJTQrnB8515RS0QjSSomcZvoal6vbW12bHXdg+hkVe1LXargNHfDgKRv 8piToMu3jBaq/BXjgGqn+rwOZPgPwB6ML2KZE/rPc5Sj6+pFN8QMu4hBaBVrVQUkJNB9 XigLkmM1udKt1ySnx07D6ne0s1i44+RZifllaukJ0JtkgDOHQ303nSRIfHsMJoYKww7u 3NEw== X-Gm-Message-State: AOAM531NwQbo+i3qQEQr7yOXLZDkEGOYIx3I++ZYc+U0RuXRHX4yG7kd +KsolVjWrwdYZ3xsbbKK9Rm/jdVOeMU3TrCo2wQz92WfXjo= X-Google-Smtp-Source: ABdhPJzi2lIsgYyB1+FFODz2f0HS7UVfvhWjzHzFP9eIS7H2KaxiKdgtGF5vEbJREo9vmRMKunPHKDCo+QQ1hRwJERc= X-Received: by 2002:a67:dc04:0:b0:328:27ea:6ecc with SMTP id x4-20020a67dc04000000b0032827ea6eccmr6639489vsj.25.1649797031847; Tue, 12 Apr 2022 13:57:11 -0700 (PDT) MIME-Version: 1.0 References: <20220412132313.39160-1-vmedvid@riseup.net> <795ccb59-38d3-a9d8-f8d4-9314689d1c62@embedded-brains.de> In-Reply-To: <795ccb59-38d3-a9d8-f8d4-9314689d1c62@embedded-brains.de> From: Volodymyr Medvid Date: Tue, 12 Apr 2022 23:57:01 +0300 Message-ID: Subject: Re: [PATCH] Fix stdio memory leaks with _REENT_SMALL + _LITE_EXIT To: Sebastian Huber Cc: newlib@sourceware.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2022 20:57:14 -0000 On Tue, 12 Apr 2022 18:10:38 +0200 Sebastian Huber wrote: > This is definitely not the right way to address this issue. > > Why don't you use the _REENT_GLOBAL_STDIO_STREAMS Newlib > configuration option? Thanks for the suggestion - I was able to verify the memory leak goes away once newlib-nano is reconfigured with "--enable-newlib-global-stdio-streams". I also see you originally submitted commit 668a4c8722090fffd10869dbb15b879651c1370d that was later extended to also apply to _REENT_SMALL (b7520b14d5fe175d9bc60266700fb7b988600a84). I filed a ticket https://bugs.linaro.org/show_bug.cgi?id=5841 to enable global stdio streams for standard newlib-nano provided with GNU Arm Embedded toolchain binary package. > This patch would break at least RTEMS. > Sorry, I have no way to validate this on any platform except Arm Cortex-M + FreeRTOS. Also, the current test suite is not capable of catching issues with stdio reentrancy. I understand there are lot of platform/OS-specific stdio implementations, some of them may rely on configure flags like "--enable-newlib-reent-small" or "--enable-lite-exit" to meet the memory and performance constraints. Unfortunately, it is not clear from the commit e7565f10886bac86410db6eb6fda47da1d04ac9b why _fclose_r was changed to _fflush_r when _LITE_EXIT is enabled - is this to reduce memory footprint? Thanks, Volodymyr