closedir() bug report (SVr3.1)
Guy Harris
guy at auspex.auspex.com
Sun Oct 29 05:15:41 AEST 1989
>>stored within it. The semantics of free doesn't guarantee data
>>integrity of freed memory.
>
>From some fairly System-Vish man pages for malloc/free:
>
> The argument to free is a pointer to a block previously allocated
> by malloc; after free is performed this space is made available
> for further allocation, but its contents are left undisturbed.
> =====================================
>
>You can claim that this is WRONG, but for compatibility I'd recommend not
>going against the grain with alternative malloc/free implementations.
And for safety I'd recommend not depending on those semantics, since:
1) the pANS doesn't require this behavior;
2) POSIX doesn't impose a requirement for it atop the ANSI C
specs;
3) the SVID only says that said behavior is required if you
explicitly use "mallopt" to set the M_KEEP flag - and, in the
section describing it, says "This option is provided only for
compatibility with the older version of the function 'malloc'
and is not recommended.";
4) the S5 "-lmalloc" routines are the ones described by the
SVID, so if you link with that library you'd better call
"mallopt" if you want to guarantee that behavior (and better
be prepared to have your code run only on systems that have
"mallopt").
4) indicates that if you don't want "closedir()" to barf, you'd better
call "mallopt" to set M_KEEP, or run your code only on systems that
guarantee it without M_KEEP (SunOS does that, although the comment in
the man page indicates that:
BUGS
Since realloc() accepts a pointer to a block freed since the
last call to malloc, calloc, realloc, valloc, or memalign, a
degradation of performance results. The semantics of free()
should be changed so that the contents of a previously freed
block are undefined.
so this may very well change in the future to require M_KEEP), or get
your vendor to fix their code not to depend on those semantics. The
first two options, of course, limit the portability of your code; your
application may well be POSIX-conforming except for that call to
"mallopt", for example.
More information about the Comp.bugs.sys5
mailing list