Gotcha.  Guess I missed that there was another copy somewhere.  I'm trying
to track down a problem with ISAPI that causes php to die and take down
everything with it.  Thought I might have a handle on it.  Thanks for the
clarification.

Joseph

> -----Original Message-----
> From: brad lafountain [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 08, 2002 4:25 PM
> To: Joseph Tate; Php-Dev List
> Subject: RE: [PHP-DEV] Memory leak and possible cause of bug #15333
>
>
> hmm
> ok
>
> zend_constant *c, *b;
> char *sname = "myname";
>
> c->name = name;         // the c->name is just a pointer to the sname
> //c->name = strdup(sname); // c->name would have it's own memory
>
> b = c; //now b->name points to sname
>
> free(b->name); // would try and free b->name which can't be done,
> segfault!
>
> so now you do this:
>
> zend_constant *c, *b;
> char *sname = "myname";
> c->name = strdup(sname); // c->name would have it's own memory
>
> b = c; //now b->name points to a copy of sname
> copy_zend_constant(b); //now b->name has its own memory
>
> free(b->name); // now this will work no segfaults here
>
> and if you look where copy_zend_constant it is only called when
> you want to
> copy constants from one hash to another.
>
>
> - Brad
> --- Joseph Tate <[EMAIL PROTECTED]> wrote:
> > I don't follow you.  Why does it need to be copied?  c->name already
> > contains the value.  Old?  New?  c is c is c.  Commenting out the code
> > causes other problems elsewhere (or seems to).  I just don't
> understand why
> > it has to be done.
> >
> > > -----Original Message-----
> > > --- Joseph Tate <[EMAIL PROTECTED]> wrote:
> > > > in the copy_zend_constant function it reads:
> > > >
> > > > void copy_zend_constant(zend_constant *c)
> > > > {
> > > >         c->name = zend_strndup(c->name, c->name_len);
> > > >         if (!(c->flags & CONST_PERSISTENT)) {
> > > >                 zval_copy_ctor(&c->value);
> > > >                 if (c->flags & CONST_EFREE_PERSISTENT) { /*
> > > persist_alloc()'d data */
> > > >                         persist_alloc(&c->value);
> > > >                 }
> > > >         }
> > > > }
> > > >
> > > > I draw your attention to the first line in the function:
> > > > c->name = zend_strndup(c->name, c->name_len);
> > > >
> > > > First of all, why is this string duplicated only to store
> it to the same
> > > > location?  Secondly, is c->name freed somewhere else?  Cause I
> > > can't see it
> > > > being freed.  Seems like this line can be removed...
> > > >
> > >
> > > So c points to the "old" value and you need to copy the name and
> > > the value to
> > > the "new" one, name and value. and the way hashes and emalloc
> > > works the memory
> > > will be freed automatically.
> > >
> > >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Tax Center - online filing with TurboTax
> http://taxes.yahoo.com/
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to