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.133.124]) by sourceware.org (Postfix) with ESMTPS id F045C3857C49 for ; Tue, 2 Aug 2022 08:03:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F045C3857C49 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-172-2oVsSvdRMzKxnkZcI2uhvg-1; Tue, 02 Aug 2022 04:03:52 -0400 X-MC-Unique: 2oVsSvdRMzKxnkZcI2uhvg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5EE1D803520; Tue, 2 Aug 2022 08:03:52 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.194.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 88915492C3B; Tue, 2 Aug 2022 08:03:51 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella Netto via Libc-alpha Subject: Re: [PATCH 1/3] stdio: Clean up __libc_message after unconditional abort References: <09db94615fe22e053d978e93e404c8a6ff64756d.1659350650.git.fweimer@redhat.com> <02dcabf5-00fd-41ac-3caf-bafb5985e382@linaro.org> Date: Tue, 02 Aug 2022 10:03:49 +0200 In-Reply-To: <02dcabf5-00fd-41ac-3caf-bafb5985e382@linaro.org> (Adhemerval Zanella Netto via Libc-alpha's message of "Mon, 1 Aug 2022 16:59:54 -0300") Message-ID: <87k07r842i.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Aug 2022 08:03:55 -0000 * Adhemerval Zanella Netto via Libc-alpha: >> + buf->size = total; >> + char *wp = buf->msg; >> + for (int cnt = 0; cnt < nlist; ++cnt) >> + wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len); >> + *wp = '\0'; >> + >> + /* We have to free the old buffer since the application might >> + catch the SIGABRT signal. */ >> + struct abort_msg_s *old = atomic_exchange_acq (&__abort_msg, >> + buf); >> + if (old != NULL) >> + __munmap (old, old->size); > > I am aware that this is just replicating the code already in place, but maybe > replace the old atomic with atomic_exchange_acquire here. We should use a CAS here anyway because the earlier message is likely more valuable for debugging purposes. The exchange was needed because when __libc_message could continue execution in the old days, we had to somehow avoid the memory leak. That's no longer a concern with the current code. I will try to clean this up further. Thanks, Florian