[freetds] Possible free(NULL) in tsql
James K. Lowden
jklowden at freetds.org
Fri Oct 12 10:32:10 EDT 2007
ZIGLIO, Frediano, VF-IT wrote:
>
> if continue at line 711 is hit s2 == NULL and a free(s2) (line 690) is
> executed. This can cause a core in some system.
Hi Freddy,
Well, I think that's a rumor, because I'm pretty sure we expect free(NULL)
to work elsewhere in the code.
I always wonder how to deal with "this code is correct but fails on some
ancient proprietary OS" concerns. Rather than avoid good code for broken
systems, I'd be happier adding an autoconf test and, if it fails,
suggesting an upgrade to any free operating system released since, oh,
1959.
But if you don't like that idea, this line 690 will work instead:
for (s2=NULL; ; free(s), s2? free(s2) : s2, s2=NULL) {
or
for (s2=NULL; ; free(s), s2? free(s2), s2=NULL : s2) {
Ah. Obscurity for the ages.
This reminds me of a larger theme, though, that I'd like to mention. I
find myself having trouble remembering portability decisions we've made,
e.g. don't cast NULL, don't (or do?) cast return from e.g. malloc(3),
don't (or do?) expect free(NULL) to work. Maybe we should collect them at
the end of doc/CodingStyle? Can you think of others?
(I remembered
http://lists.ibiblio.org/pipermail/freetds/2003q1/012125.html but had to
do some digging to find it!)
Regards,
--jkl
More information about the FreeTDS
mailing list