From owner-freebsd-current@FreeBSD.ORG Mon Oct 4 17:22:27 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BF51216A4CE for ; Mon, 4 Oct 2004 17:22:27 +0000 (GMT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3BCAD43D46 for ; Mon, 4 Oct 2004 17:22:27 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.11/8.12.11) id i94HMOJN024300; Mon, 4 Oct 2004 12:22:24 -0500 (CDT) (envelope-from dan) Date: Mon, 4 Oct 2004 12:22:24 -0500 From: Dan Nelson To: Brian Reichert Message-ID: <20041004172224.GA30419@dan.emsphone.com> References: <20041004171422.GK262@numachi.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20041004171422.GK262@numachi.com> X-OS: FreeBSD 5.3-BETA6 X-message-flag: Outlook Error User-Agent: Mutt/1.5.6i cc: freebsd-current@freebsd.org Subject: Re: awk leaking memory during arithmetic? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Oct 2004 17:22:27 -0000 In the last episode (Oct 04), Brian Reichert said: > I may be misremembering some awk lore, but this still seems like > undesired behavior. Essentially, I'm trying to sum up some numbers, > but awk spin, chewing up memory, until it drops a huge core file. > > # uname -a > FreeBSD backup.internal 5.2.1-RELEASE FreeBSD 5.2.1-RELEASE #1: Mon Sep 27 > 19:27:46 EDT 200 root@backup2.internal:/usr/src/sys/i386/compile/FILESERVER i386 > > # cat test_list | awk '{print $1}' > 53999616 > 53999616 > 53311488 > 102475776 > 257134592 > 858624 > 512909312 > 1147392 > 39385174 > 35815424 > > # cat test_list | awk '{ t += $1 } END {print $t}' > awk in malloc(): error: allocation failed I think "print t" is what you want here. $t would refer to the t'th field in the line, and it looks like awk tried to resize the array out to 1111037014 entries and failed. -- Dan Nelson dnelson@allantgroup.com