[PATCH 1 of 4 lazy-manifest] manifest.c: new extension code to lazily parse manifests

Martin von Zweigbergk martinvonz at google.com
Fri Jan 9 19:13:32 CST 2015


On Fri Jan 09 2015 at 5:06:55 PM Augie Fackler <raf at durin42.com> wrote:

>
> On Jan 9, 2015, at 8:02 PM, Martin von Zweigbergk <martinvonz at google.com>
> wrote:
>
> >
> >
> > On Thu Jan 08 2015 at 12:35:42 PM Augie Fackler <raf at durin42.com> wrote:
> > +static lazymanifest *lzm_copy(lazymanifest * self, PyObject *
> unused_args)
> > +{
> > +       lazymanifest *copy = NULL;
> > +       if (compact(self) != 0) {
> > +               goto nomem;
> > +       }
> > +       copy = PyObject_New(lazymanifest, &lazymanifestType);
> > +       if (copy == NULL) {
> > +               goto nomem;
> > +       }
> > +       copy->numlines = self->numlines;
> > +       copy->livelines = self->livelines;
> > +       copy->dirty = false;
> > +       copy->lines = malloc(self->maxlines * sizeof(line));
> > +       if (copy->lines == NULL) {
> > +               goto nomem;
> > +       }
> > +       memcpy(copy->lines, self->lines, self->numlines * sizeof(line));
> >
> > If some of the lines have from_malloc=true, and either the original or
> the copy gets GC'ed (so lzm_dealloc gets called), then the other copy will
> end up with pointers into free'd memory, no?
>
> No, because we always call compact(self) before making the copy, so we
> know we don’t have any from_malloc lines. Does that make sense?
>

Yes, that's what I was missing, thanks. (I checked callers of lzm_copy(),
but it happens within lzm_copy() itself, which makes sense.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20150110/60a0a0fe/attachment.html>


More information about the Mercurial-devel mailing list