manifest.c needs an eyeball or two

Martin von Zweigbergk martinvonz at google.com
Thu Dec 31 21:59:15 CST 2015


I don't know what error you are seeing, but it looks like you have two
Py_DECREF(arg) there now. Could that be the problem?

On Thu, Dec 31, 2015, 11:01 Augie Fackler <raf at durin42.com> wrote:

> I clearly have a case of the dumb. I tried to fix this, and all I can do
> is get segfaults out the other end. Here’s what I’ve got after some beating
> my head against the wall:
>
> diff --git a/mercurial/manifest.c b/mercurial/manifest.c
> --- a/mercurial/manifest.c
> +++ b/mercurial/manifest.c
> @@ -704,9 +704,19 @@ static lazymanifest *lazymanifest_filter
>         copy->pydata = self->pydata;
>         Py_INCREF(self->pydata);
>         for (i = 0; i < self->numlines; i++) {
> -               PyObject *arg = PyString_FromString(self->lines[i].start);
> -               PyObject *arglist = PyTuple_Pack(1, arg);
> -               PyObject *result = PyObject_CallObject(matchfn, arglist);
> +               PyObject *arg = NULL, *arglist = NULL, *result = NULL;
> +               arg = PyString_FromString(self->lines[i].start);
> +               if (!arg) {
> +                       PyErr_SetString(PyExc_TypeError,
> +                                       "couldn't pack filename");
> +                       return NULL;
> +               }
> +               arglist = PyTuple_Pack(1, arg);
> +               Py_DECREF(arg);
> +               if (!arglist) {
> +                       return NULL;
> +               }
> +               result = PyObject_CallObject(matchfn, arglist);
>                 Py_DECREF(arglist);
>                 Py_DECREF(arg);
>                 /* if the callback raised an exception, just let it
>
> (I found a handful of other non-checked error returns, but this one is
> causing problems if I try and fix it.)
>
> > On Dec 12, 2015, at 11:07 PM, Bryan O'Sullivan <bos at serpentine.com>
> wrote:
> >
> > Looking at use of some Python/C API functions, there are a few return
> values unchecked.
> >
> > For instance, the first call to PyString_FromString in
> lazymanifest_filtercopy.
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20160101/9beff6ea/attachment.html>


More information about the Mercurial-devel mailing list