Opened 12 years ago

Closed 9 years ago

#1547 closed defect (invalid)

Patch for mingw bug in strdup

Reported by: Mateusz Łoskot Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: 1.4.0
Severity: normal Keywords:
Cc: rob.mcmullen@…, Daniel Morissette

Description

NOTE: This patch was posted on the gdal-dev by Rob McMullen?


Using MinGW, there's a really strange bug that I can't yet isolate completely, but occurs within msvcrt's strdup implementation. Enclosed is a patch to duplicate the functionality of strdup but using VSIMalloc, avoiding the problematic strdup.

If you didn't want to use this to replace strdup entirely, you could wrap the new code with ifdefs:

#if defined(WIN32) && defined(GCC)

which should isolate this to MinGW only.

Rob

Attachments (1)

strdup-mingw-bug.patch (612 bytes) - added by Mateusz Łoskot 12 years ago.
Patch fixing reported issue

Download all attachments as: .zip

Change History (6)

Changed 12 years ago by Mateusz Łoskot

Attachment: strdup-mingw-bug.patch added

Patch fixing reported issue

comment:3 Changed 12 years ago by warmerdam

While the suggested patch looks relatively harmless, I find it hard to imagine that strdup() is really broken, or that the malloc() used by VSIMalloc() is going to give a different kind of memory (ie. different heap) than what is returned by strdup(). So I'm not prepared to take any action on this without better information to reproduce the problem - followed by an analysis of the root of the problem.

I'll leave this open for a bit in case you want to follow up with more info. Otherwise I'll close it in a bit.

comment:4 Changed 12 years ago by robm

I understand your skepticism, but this is a real problem, and the patch fixed it. Obviously MinGW isn't a commonly used platform, so this isn't critical for anyone but me, probably. I was having a very difficult time debugging it at first, because I was using it through ngpython's swig interface and couldn't debug it with either gdb or ms tools. 150 debug print statements later, I isolated the strdup problem. Now that I know that it's not in the python part, I can write a test using C++ that doesn't mix code with the msvcrt code in Python. That I should be able to debug using gdb.

comment:5 Changed 12 years ago by Mateusz Łoskot

Rob, I have taken some time to research this problem with Google and I'm inclined to state that this is but is related to MinGW, but to GDAL.

As I found, there are plenty of crash reports when using strdup/free with MinGW. Obviously, there are incompatibilities between C/C++ libraries.

I'm not going to judge if it's worth to apply your patch to GDAL or not, but I'd suggest you to write about this to MinGW list as well, may be there are some patches or resolutions well known.

comment:6 Changed 12 years ago by Daniel Morissette

Cc: Daniel Morissette added

comment:7 Changed 9 years ago by Even Rouault

Resolution: invalid
Status: newclosed

I haven't had any problem with recent MinGW. Must have been fixed since then.

Note: See TracTickets for help on using tickets.