Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Sep 1997 00:19:45 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        cmf@netins.net (Carl Fongheiser)
Cc:        tlambert@primenet.com, freebsd-hackers@freebsd.org
Subject:   Re: Memory leak in getservbyXXX?
Message-ID:  <199709130019.RAA23474@usr04.primenet.com>
In-Reply-To: <v03102800b03f82900eec@[44.50.32.7]> from "Carl Fongheiser" at Sep 12, 97 06:40:53 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> >The use of static data buffers in libc is a long-standing abomination,
> >blessed by ANSI and codified in stone by POSIX.  Assume any man page
> >which states a pointer to a static data area is returned is actually
> >allocating a data area and expecting the caller to free it, whenever
> >you are using a thread-safe library.
> 
> It may be an abomination, but it's also a fact of life.

The correct fix is to change the standards so that it isn't.  I know,
I know, not going to happen... only Microsoft ever gets rid of legacy
interfaces, it seems.


> The pthread
> interface *does* provide a way to cope -- check out pthread_key_create(),
> pthread_setspecific() and pthread_getspecific().  You even get to specify
> a destructor routine, so you can automagically clean up your allocated
> buffers inside the library!

This is more than somewhat Evil.

Specifically, the concept of marshalling objects between threads only
starts to get really complicated if you do something stupid (like
Microsoft did) and start allocating objects into thread local storage,
such that there is no guarantee that the thread address spaces are
common.

A threads aware C++ object class using a pure virtual interface
class (can you say COM?) will have a bitch of a time using objects
created by one thread in another thread if the backing objects for
the interface class are instanced in a thread other than the one in
which they are to be used.  This is why CoCreateFreeThreadedMarshaller()
exists.  I would prefer that FreeBSD not become Windows, at least not
at the "terrible API" layer.  8-|.

I would much prefer that the standard library routines *NOT* attempt
to grandfather badly designed interfaces, the better to keep them
hung, as an albatross about our necks, until the end of time.  If
we wanted to be Ancient Mariners, we would all be programming to
the NetWare API set, which grandfathers back to version 1.0 of NetWare.
8-(.


					Regards,
					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199709130019.RAA23474>