Ok, I've been starring at this code, and I think that I understand it  
now.

The question I have is this.

I can see where the memory that was alloc'd for the environmental  
variable.  I can see where the memory is free'd.  But I don't see  
where the pointer to the memory is set to a null-pointer value.  So  
the array of pointers, still has a pointer to the free'd memory.  Does  
that make sense?

Bruce
On Sep 30, 2009, at 8:15 PM, Mark Miesfeld wrote:

> On Wed, Sep 30, 2009 at 4:06 PM, Rick McGuire  
> <[email protected]> wrote:
>
>> Nope, other than to point to the code responsible.  This is handled  
>> in
>> interpreter/platform/unix/ValueFunction.cpp.
>
> A while back we added this code in PlatformDefinitions.h:
>
> #ifdef __APPLE__
> # include <crt_externs.h>
> inline char **getEnvironment()
> {
>     return (*_NSGetEnviron());
> }
> #else
> inline char **getEnvironment()
> {
>   extern char **environ;
>   return environ;
> }
> #endif
>
> So, on OS X they are doing things slightly different and I guess that
> is at the bottom of this.  If I had a Mac to work on, I probably could
> eventually figure this out, through brute force if nothing else.  I'm
> not too good at theoretically figuring this out.  <grin>
>
> For the unix ValueFunction.cpp in SetEnvrionmentVariable(), there is
> this code that loops through every variable and compares the name
> portion to the name passed in.  If / when it finds a match, it marks
> it for deletion:
>
> for(;*Environment != NULL;Environment++){
>  np = *Environment;
>                                     /* extract the the  
> name              */
>                                     /* from the current env  
> string       */
>  for(i=0;(*np!='=')&&(i<255);np++,i++){
>    memcpy(&(namebufcurr[i]),np,1);  /* copy the  
> character                */
>  }
>  memcpy(&(namebufcurr[i]),"\0",1);      /* copy the  
> terminator           */
>
>  if(!strcmp(Name->getStringData(),namebufcurr))/* have a  
> match ?         */
>    del = *Environment;              /* remember it for  
> deletion          */
> }
>
> Then, if the new value is not .nil it uses putevn() to add a new
> string to the environ:
>
>  if (Value != (RexxString *) TheNilObject)
>  {
>    sprintf(Env_Var_String,
> "%s=%s",Name->getStringData(),Value->getStringData());
>    putenv(Env_Var_String);
>  }
>
> and if the name was found, the old name=value string is always freed:
>
>  if(del)                              /* if there was a old  
> one            */
>    free(del);                         /* free  
> it                           */
>
> I don't understand how that works.  It obviously does on Linux, I just
> walked through it.  But, it is freeing some malloc'd memory, it
> doesn't change anything.  I don't see how that removes it from
> environ.
>
> So, I'm lost.  I don't even really understand why it works on Linux.
>
> --
> Mark Miesfeld
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart  
> your
> developing skills, take BlackBerry mobile applications to market and  
> stay
> ahead of the curve. Join us from November 9&#45;12, 2009. Register  
> now&#33;
> http://p.sf.net/sfu/devconf
> _______________________________________________
> Oorexx-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Oorexx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to