[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:02:17 CST 2015


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?

We could fix by allocating a separate copy for such lines. Probably simpler
than replacing the boolean from_malloc by an integer for reference-counting.

+       copy->maxlines = self->maxlines;
> +       copy->pydata = self->pydata;
> +       Py_INCREF(copy->pydata);
> +       return copy;
> +nomem:
> +       PyErr_NoMemory();
> +       Py_XDECREF(copy);
> +       return NULL;
> +}
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20150110/43ebf036/attachment.html>


More information about the Mercurial-devel mailing list