Opened 21 years ago

Closed 21 years ago

#413 closed defect (fixed)

msGetErrorString causes segfaults on Linux inside Python MapScript exceptions

Reported by: sgillies@… Owned by: sdlime
Priority: high Milestone:
Component: MapServer C Library Version: 4.0
Severity: normal Keywords:
Cc: mschulz@…

Description

A Python MapScript user on Linux (Michael Schultz) has reported consistent 
segmentation faults when MapScript raises exceptions.  The problem appears
to be with msGetErrorString, or the way it is used in the SWIG exception
wrapper.

I have rolled back the code in CVS branch-4-0 to the previous state before
msGetErrorString was introduced and this is once again working for Michael.

In this older code, there is just one single call to msGetErrorObj per
exception.

In the new (buggy?) code, there is at least two calls to msGetErrorObj
with one in msGetErrorString.

I never experienced any problems with using msGetErrorString and I'm
beginning to wonder if it is a threading problem.  Michael has not yet
confirmed whether he was using a MapServer configured --with-threads.

Change History (2)

comment:1 by sdlime, 21 years ago

I've compared the code in msGetErrorString with similar string handling 
functions elsewhere in the distribution (written by different authors) and it 
seems sound. I'll check again to be sure. Some questions:

  - Sean was your code free'ing the string returned by the function?
  - What platform are we talking about?

Steve

comment:2 by sgillies@…, 21 years ago

Resolution: fixed
Status: newclosed
Steve,

Sorry to alarm you.  I entered this bug so that I'd be motivated to find the
solution, not to make you look into msGetErrorString.

The function appears to be OK, it was just a matter of how I'd been calling
it.  I'm not sure why it wasn't segfaulting on my Mac.  The issue that 
Michael had reported to me on Linux is fixed by using msGetErrorString in
this way:
 
        switch (errcode) {
            case MS_IOERR:
                PyErr_SetString(PyExc_IOError, msGetErrorString("\n"));
                break;
            case MS_MEMERR:
                PyErr_SetString(PyExc_MemoryError, msGetErrorString("\n"));
                break;
            case MS_TYPEERR:
                PyErr_SetString(PyExc_TypeError, msGetErrorString("\n"));
                break;
            case MS_EOFERR:
                PyErr_SetString(PyExc_EOFError, msGetErrorString("\n"));
                break;
            case MS_NOTFOUND:
                PyErr_SetString(MSExc_MapServerNotFoundError,
msGetErrorString("\n"));
                break;

I've verified that it works on a client's RH Linux machine this afternoon.

Note: See TracTickets for help on using tickets.