From owner-freebsd-current@FreeBSD.ORG Fri Apr 27 01:10:35 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2816C16A401 for ; Fri, 27 Apr 2007 01:10:35 +0000 (UTC) (envelope-from sean-freebsd@farley.org) Received: from mail.farley.org (farley.org [67.64.95.201]) by mx1.freebsd.org (Postfix) with ESMTP id EA59213C43E for ; Fri, 27 Apr 2007 01:10:34 +0000 (UTC) (envelope-from sean-freebsd@farley.org) Received: from thor.farley.org (thor.farley.org [192.168.1.5]) by mail.farley.org (8.14.1/8.14.1) with ESMTP id l3R1BESr091318 for ; Thu, 26 Apr 2007 20:11:14 -0500 (CDT) (envelope-from sean-freebsd@farley.org) Date: Thu, 26 Apr 2007 20:10:29 -0500 (CDT) From: "Sean C. Farley" To: freebsd-current@freebsd.org Message-ID: <20070426195122.P37719@thor.farley.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Subject: setenv memory leak fix (take 3) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 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: Fri, 27 Apr 2007 01:10:35 -0000 I have a new version[1] of my fix for the memory leak in setenv(), unsetenv() and putenv(). Changes: 1. Fix for the rebuilding of environ after a new variable slot is added. I noticed this when Java was stuck in an endless loop. It was not rebuilding environ when it should have. Java needs environ to execve() itself with LD_LIBRARY_PATH defined with its library directories prefixed to the existing value. It never saw the change, so it tried continuously. 2. Speed tweaks. inline'ing helped a bit. Here are some timings I took with the current code in FreeBSD and my last two versions. Each call is executed 1000000 times and the results are in seconds. The latest code is comparable for getenv() to the current code base but setenv() is much faster. This test does not perform alternating between different size values. Current Take 2 Take 3 -------- -------- -------- getenv(name): 0.112457 0.216450 0.070750 setenv(name, value1, 1): 0.542081 0.491348 0.256943 getenv(name): 0.107742 0.256953 0.095008 getenv(name2): 0.157418 0.342412 0.122382 setenv(name, value2, 1): 0.389988 0.411441 0.169207 getenv(name): 0.156040 0.347334 0.121014 getenv(name2): 0.145866 0.345817 0.119156 Are there any opinions on having unsetenv() return a value to match unsetenv() in IEEE Std 1003.1? Sean 1. http://www.farley.org/freebsd/tmp/setenv-7/ -- sean-freebsd@farley.org