[Gdal-dev] Re: patch for mingw bug in strdup

Rob McMullen rob.mcmullen at gmail.com
Wed Mar 28 07:21:22 EDT 2007


Following up on my own post...

> Using MinGW, there's a really strange bug that I can't yet isolate
> completely, but occurs within msvcrt's strdup implementation.

Actually, having slept on it, what I suspect is going on in that the
memory returned by msvnrt's strdup is not from the same pool as the
memory returned by malloc, so performing a realloc on a string
initially allocated by strdup is causing problems.

It seems that the single unix specification is ambiguous about strdup
and realloc:

http://www.opengroup.org/onlinepubs/009695399/functions/strdup.html

although given that it does say that the pointer returned by strdup
can be passed to free one would assume it would work to realloc...
unless the platform's implementation of free were smart enough to know
it was dealing with different pools of heap storage.

So, maybe it's worth it to use the strdup written using VSIMalloc
since it seems that the standard is ambiguous.

Rob



More information about the Gdal-dev mailing list