comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: IDL/DLM segmentation fault on reset
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: IDL/DLM segmentation fault on reset [message #72311] Tue, 31 August 2010 08:24 Go to next message
Haje Korth is currently offline  Haje Korth
Messages: 651
Registered: May 1997
Senior Member
Hi Karl,
thanks so much for your reply. You are exactly right, the variable
input to putenv is a static char*, and your description of what is
going on makes sense. I will give setenv a shot later today and report
back.

Cheers,
haje


On Aug 31, 10:54 am, Karl <karl.w.schu...@gmail.com> wrote:
> On Aug 30, 6:34 pm, Haje Korth <hajeko...@gmail.com> wrote:
>
>> Hi,
>> Have an interesting problem for DLM programmers out there. I have a C
>> code for Linux that sets an environment variable using putenv() within
>> a DLM. The code executes as designed but when I issue
>> a .full_session_reset I get a segmentation fault and IDL exits
>> ungracefully. I run the same code (with slightly different calling
>> convention) under Windows without problems. Does anyone know why? Do I
>> need some sort of exit handler for the DLM (similar to IDL_Load for
>> startup)?
>
>> Haje
>
> The putenv() function just puts a pointer to the string in the
> environment.  It does not make a copy of the string.
>
> The full session reset unloads the DLM.  Your string argument to
> putenv() probably resides in a static var in the DLM.  The environment
> is just a list of pointers to strings.  When the DLM got unloaded, the
> environment is left with an invalid pointer to a string.  I can't say
> exactly what was going on when the segmentation fault occurred, but it
> is easy to imagine that some system routine running during the session
> reset was probably walking the environment strings and hit the bogus
> pointer.
>
> You might try using setenv() instead.  The setenv() function allocates
> heap memory for environment strings, and thus avoids the string memory
> from getting unallocated by a unload of a module or an automatic
> variable going out of scope.
>
> It worked on Windows because Windows probably stores the environment
> strings differently.
>
> Karl
Re: IDL/DLM segmentation fault on reset [message #72312 is a reply to message #72311] Tue, 31 August 2010 07:54 Go to previous messageGo to next message
Karl[1] is currently offline  Karl[1]
Messages: 79
Registered: October 2005
Member
On Aug 30, 6:34 pm, Haje Korth <hajeko...@gmail.com> wrote:
> Hi,
> Have an interesting problem for DLM programmers out there. I have a C
> code for Linux that sets an environment variable using putenv() within
> a DLM. The code executes as designed but when I issue
> a .full_session_reset I get a segmentation fault and IDL exits
> ungracefully. I run the same code (with slightly different calling
> convention) under Windows without problems. Does anyone know why? Do I
> need some sort of exit handler for the DLM (similar to IDL_Load for
> startup)?
>
> Haje

The putenv() function just puts a pointer to the string in the
environment. It does not make a copy of the string.

The full session reset unloads the DLM. Your string argument to
putenv() probably resides in a static var in the DLM. The environment
is just a list of pointers to strings. When the DLM got unloaded, the
environment is left with an invalid pointer to a string. I can't say
exactly what was going on when the segmentation fault occurred, but it
is easy to imagine that some system routine running during the session
reset was probably walking the environment strings and hit the bogus
pointer.

You might try using setenv() instead. The setenv() function allocates
heap memory for environment strings, and thus avoids the string memory
from getting unallocated by a unload of a module or an automatic
variable going out of scope.

It worked on Windows because Windows probably stores the environment
strings differently.

Karl
Re: IDL/DLM segmentation fault on reset [message #72405 is a reply to message #72311] Tue, 31 August 2010 13:08 Go to previous message
Haje Korth is currently offline  Haje Korth
Messages: 651
Registered: May 1997
Senior Member
Just FYI: I confirm that replacing putenv() with setenv() avoids the
segmentation fault on IDL session reset. I do not think this routine
exists in Visual Studio. However, putenv did not create any issues on
windows.

Haje

On Aug 31, 11:24 am, Haje Korth <hajeko...@gmail.com> wrote:
> Hi Karl,
> thanks so much for your reply. You are exactly right, the variable
> input to putenv is a static char*, and your description of what is
> going on makes sense. I will give setenv a shot later today and report
> back.
>
> Cheers,
> haje
>
> On Aug 31, 10:54 am, Karl <karl.w.schu...@gmail.com> wrote:
>
>> On Aug 30, 6:34 pm, Haje Korth <hajeko...@gmail.com> wrote:
>
>>> Hi,
>>> Have an interesting problem for DLM programmers out there. I have a C
>>> code for Linux that sets an environment variable using putenv() within
>>> a DLM. The code executes as designed but when I issue
>>> a .full_session_reset I get a segmentation fault and IDL exits
>>> ungracefully. I run the same code (with slightly different calling
>>> convention) under Windows without problems. Does anyone know why? Do I
>>> need some sort of exit handler for the DLM (similar to IDL_Load for
>>> startup)?
>
>>> Haje
>
>> The putenv() function just puts a pointer to the string in the
>> environment.  It does not make a copy of the string.
>
>> The full session reset unloads the DLM.  Your string argument to
>> putenv() probably resides in a static var in the DLM.  The environment
>> is just a list of pointers to strings.  When the DLM got unloaded, the
>> environment is left with an invalid pointer to a string.  I can't say
>> exactly what was going on when the segmentation fault occurred, but it
>> is easy to imagine that some system routine running during the session
>> reset was probably walking the environment strings and hit the bogus
>> pointer.
>
>> You might try using setenv() instead.  The setenv() function allocates
>> heap memory for environment strings, and thus avoids the string memory
>> from getting unallocated by a unload of a module or an automatic
>> variable going out of scope.
>
>> It worked on Windows because Windows probably stores the environment
>> strings differently.
>
>> Karl
>
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Insert an image in Excel
Next Topic: ITT Announces Acquisition of CREASO

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 12:52:49 PDT 2025

Total time taken to generate the page: 1.20142 seconds