From owner-freebsd-current@FreeBSD.ORG Mon Oct 4 17:14:23 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 E498316A4CE for ; Mon, 4 Oct 2004 17:14:23 +0000 (GMT) Received: from mail2.numachi.com (mail2.numachi.com [198.175.254.8]) by mx1.FreeBSD.org (Postfix) with SMTP id 0EDA243D46 for ; Mon, 4 Oct 2004 17:14:23 +0000 (GMT) (envelope-from reichert@numachi.com) Received: (qmail 10504 invoked from network); 4 Oct 2004 17:14:22 -0000 Received: from natto.numachi.com (198.175.254.216) by mail2.numachi.com with SMTP; 4 Oct 2004 17:14:22 -0000 Received: (qmail 33884 invoked by uid 1001); 4 Oct 2004 17:14:22 -0000 Date: Mon, 4 Oct 2004 13:14:22 -0400 From: Brian Reichert To: freebsd-current@freebsd.org Message-ID: <20041004171422.GK262@numachi.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.6i Subject: 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:14:24 -0000 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 Abort (core dumped) # ls -l awk.core -rw------- 1 root wheel 537698304 Oct 4 12:58 awk.core Changing the awk program thusly: cat test_list | awk '{ t += "$1" } END {print $t }' Stops the malloc errors, but now prints nothing. This same test on 4.10-RELEASE also doesn't do what I expect: % cat test_list | awk '{ t += $1 } END {print $t}' % Just prints a blank line, with a zero exit status. Adding the quotes as above, yeilds some bad math, which I presume is some overflow error: % cat test_list | awk '{ t += "$1" } END {print $t}' 35815424 I note that 5.2.1 and 4.10 are using different versions of awk. Are these awk bugs, or am I misusing awk? The memory consumption under 5.2.1 is what concerns me the most. I'll open a PR, if that's the concensus. This sypmtom doesn't seem to correspond to any of the (closed) PRs about awk... -- Brian Reichert 37 Crystal Ave. #303 Daytime number: (603) 434-6842 Derry NH 03038-1713 USA BSD admin/developer at large