Date: Thu, 06 Aug 1998 05:38:48 -0700 From: David Greenman <dg@root.com> To: Narvi <narvi@haldjas.folklore.ee> Cc: Bruce Evans <bde@zeta.org.au>, freebsd@xaa.iae.nl, freebsd-current@FreeBSD.ORG Subject: Re: memory leaks in libc Message-ID: <199808061238.FAA28204@implode.root.com> In-Reply-To: Your message of "Thu, 06 Aug 1998 15:24:08 %2B0300." <Pine.BSF.3.96.980806152019.9173B-100000@haldjas.folklore.ee>
next in thread | previous in thread | raw e-mail | index | archive | help
>> > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808061238.FAA28204>