From owner-freebsd-bugs Sat Jun 15 0:50:10 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id B16B737B408 for ; Sat, 15 Jun 2002 00:50:03 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g5F7o3O07077; Sat, 15 Jun 2002 00:50:03 -0700 (PDT) (envelope-from gnats) Date: Sat, 15 Jun 2002 00:50:03 -0700 (PDT) Message-Id: <200206150750.g5F7o3O07077@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: David Greenman-Lawrence Subject: Re: misc/39314: Memory leak in setenv Reply-To: David Greenman-Lawrence Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR misc/39314; it has been noted by GNATS. From: David Greenman-Lawrence To: Nathan Mower Cc: freebsd-gnats-submit@FreeBSD.org Subject: Re: misc/39314: Memory leak in setenv Date: Sat, 15 Jun 2002 00:44:45 -0700 >>Description: > There is a memory leak in setenv in the case where a name/value pair already exists and the new value is larger than the old one. Setenv does not free the old memory before it malloc's space for the new string. >>How-To-Repeat: > setenv("HOME", "/usr/home/abc", 1); > setenv("HOME", "/usr/home/abcdefghijklmnopqrstuvwxyz", 1); >>Fix: > free the old environ[offset] before malloc'ing the new one. This is a well known and unfixable problem. The problem is that environment data may not (and often is not) allocated by malloc - you just don't know, so you can't free it. This is mentioned in the BUGS section in the setenv.3 manual page, although the description of the problem is misleading. -DG D.G.Lawrence Download Technologies, Inc. - http://www.downloadtech.com - (866) 399 8500 TeraSolutions, Inc. - http://www.terasolutions.com - (503) 288 9544 The FreeBSD Project - http://www.freebsd.org Pave the road of life with opportunities. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message