manifest.c needs an eyeball or two
Augie Fackler
raf at durin42.com
Thu Dec 31 19:00:22 UTC 2015
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20151231/8607edab/attachment.pgp>
More information about the Mercurial-devel
mailing list