From patchwork Thu Jul 22 13:24:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 44453 X-Patchwork-Delegate: carlos@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ABBBC382CC09 for ; Thu, 22 Jul 2021 13:26:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABBBC382CC09 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1626960377; bh=wOGiQhSdjFYZovZ2dpQaAxr7QNzkbsVHu8pdLgjNxAM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=x7yiMNMP2+ksnct+SW/3rfjINmka1meFItuMmK/0ejweflkeByKsjcX2q+IgUzFzk C48r2ZTMpY6ap00+ru17aS/LiUwrxqaXiEdlYwxNVFIpF6/L1ufwIRvoop/mfO2bo9 7tTc0C2tFh1hELLCNOcGW9CA8oHMXexYR+ErAL/U= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from butterfly.birch.relay.mailchannels.net (butterfly.birch.relay.mailchannels.net [23.83.209.27]) by sourceware.org (Postfix) with ESMTPS id 2A4B0384780F for ; Thu, 22 Jul 2021 13:24:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2A4B0384780F X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 2172C341DA1; Thu, 22 Jul 2021 13:24:55 +0000 (UTC) Received: from pdx1-sub0-mail-a10.g.dreamhost.com (100-98-55-150.trex.outbound.svc.cluster.local [100.98.55.150]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 936173425D8; Thu, 22 Jul 2021 13:24:54 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a10.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.98.55.150 (trex/6.3.3); Thu, 22 Jul 2021 13:24:54 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Abiding-Share: 18053ad3018af3b1_1626960294854_2877143553 X-MC-Loop-Signature: 1626960294854:3233325705 X-MC-Ingress-Time: 1626960294854 Received: from pdx1-sub0-mail-a10.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTP id 021557EFD2; Thu, 22 Jul 2021 06:24:46 -0700 (PDT) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTPSA id 991B27EFC9; Thu, 22 Jul 2021 06:24:42 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a10 To: libc-alpha@sourceware.org Subject: [PATCH] mtrace: Use a static buffer for printing [BZ #25947] Date: Thu, 22 Jul 2021 18:54:30 +0530 Message-Id: <20210722132430.1945153-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3484.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, UNWANTED_LANGUAGE_BODY 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: 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-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Use a static buffer for mtrace printing now that it no longer adds to default libc footprint. Reviewed-by: DJ Delorie --- malloc/mtrace-impl.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/malloc/mtrace-impl.c b/malloc/mtrace-impl.c index 0e10ab7f60..83008ca18f 100644 --- a/malloc/mtrace-impl.c +++ b/malloc/mtrace-impl.c @@ -34,11 +34,8 @@ #include -#define TRACE_BUFFER_SIZE 512 - static FILE *mallstream; static const char mallenv[] = "MALLOC_TRACE"; -static char *malloc_trace_buffer; static void tr_where (const void *caller, Dl_info *info) @@ -184,16 +181,13 @@ do_mtrace (void) mallfile = secure_getenv (mallenv); if (mallfile != NULL) { - char *mtb = malloc (TRACE_BUFFER_SIZE); - if (mtb == NULL) - return; - mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "wce"); if (mallstream != NULL) { /* Be sure it doesn't malloc its buffer! */ - malloc_trace_buffer = mtb; - setvbuf (mallstream, malloc_trace_buffer, _IOFBF, TRACE_BUFFER_SIZE); + static char tracebuf [512]; + + setvbuf (mallstream, tracebuf, _IOFBF, sizeof (tracebuf)); fprintf (mallstream, "= Start\n"); if (!added_atexit_handler) { @@ -203,8 +197,6 @@ do_mtrace (void) } __malloc_debug_enable (MALLOC_MTRACE_HOOK); } - else - free (mtb); } }