Skip to Content.
Sympa Menu

freetds - Re: [freetds] Possible free(NULL) in tsql

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT freetds.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Possible free(NULL) in tsql
  • Date: Fri, 12 Oct 2007 10:32:10 -0400

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
https://lists.ibiblio.org/sympa/arc/freetds/2003q1/012125.html but had to
do some digging to find it!)

Regards,

--jkl






Archive powered by MHonArc 2.6.24.

Top of Page