From owner-freebsd-current Thu Aug 6 05:44:02 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id FAA29580 for freebsd-current-outgoing; Thu, 6 Aug 1998 05:44:02 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from implode.root.com (implode.root.com [198.145.90.17]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id FAA29544 for ; Thu, 6 Aug 1998 05:43:54 -0700 (PDT) (envelope-from root@implode.root.com) Received: from implode.root.com (localhost [127.0.0.1]) by implode.root.com (8.8.5/8.8.5) with ESMTP id FAA28204; Thu, 6 Aug 1998 05:38:48 -0700 (PDT) Message-Id: <199808061238.FAA28204@implode.root.com> To: Narvi cc: Bruce Evans , freebsd@xaa.iae.nl, freebsd-current@FreeBSD.ORG Subject: Re: memory leaks in libc In-reply-to: Your message of "Thu, 06 Aug 1998 15:24:08 +0300." From: David Greenman Reply-To: dg@root.com Date: Thu, 06 Aug 1998 05:38:48 -0700 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >> > The problem with fixing setenv() is that you don't know if a pointer was >> >malloced, allocated from the env area above the stack, points to read-only >> >text, points to a static data buffer, etc. There really is no way to know >> >for sure, so you can't free the memory. >> >> Yo can know if you malloced it in a previous call to putenv() or setenv(). >> >> Bruce > >So we could: > > a) allocate a bit more memory than needed > b) set the environment string > c) end it with zero > d) append a certain token after the end of the string saying "ok > to free() me" to anyone knowing what to look at? > >But couldn't a string end at the end of allocated area so that by peeking >behind the final zero we will sometimes cause a SIGSEV? Perhaps Bruce is suggesting that a seperate array be allocated to keep track of whether or not an env pointer was malloced? This would be very costly and, IMO, not worth it considering how rarely memory is lost by not freeing previously malloced strings. -DG David Greenman Co-founder/Principal Architect, The FreeBSD Project To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message