Skip to content

Commit e8f8d0f

Browse files
committed
pull PyCapsule_New() into the PYLOCK() section in poll_func()
If we call PyCapsule_New() from a thread created by libfuse before ensuring the python interpreter is initialized, the thread state will be NULL and the program will crash with SEGFAULT. As suggested by David Lechner: pull the call to PyCapsule_New() into the PYLOCK() section and open-code the rest of what was previously in the PROLOGUE() macro. Closes: #82
1 parent b330bcc commit e8f8d0f

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

fuseparts/_fusemodule.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,15 +1272,31 @@ poll_func(const char *path, struct fuse_file_info *fi,
12721272
struct fuse_pollhandle *ph, unsigned *reventsp)
12731273
{
12741274
PyObject *pollhandle = Py_None;
1275+
int ret = -EINVAL;
1276+
PyObject *v;
1277+
1278+
PYLOCK();
12751279

12761280
if (ph)
12771281
pollhandle = PyCapsule_New(ph, pollhandle_name, pollhandle_destructor);
12781282

12791283
#ifdef FIX_PATH_DECODING
1280-
PROLOGUE(PYO_CALLWITHFI(fi, poll_cb, O&O, &Path_AsDecodedUnicode, path, pollhandle));
1284+
v = PYO_CALLWITHFI(fi, poll_cb, O&O, &Path_AsDecodedUnicode, path, pollhandle);
12811285
#else
1282-
PROLOGUE(PYO_CALLWITHFI(fi, poll_cb, sO, path, pollhandle));
1286+
v = PYO_CALLWITHFI(fi, poll_cb, sO, path, pollhandle);
12831287
#endif
1288+
if (!v) {
1289+
PyErr_Print();
1290+
goto OUT;
1291+
}
1292+
if (v == Py_None) {
1293+
ret = 0;
1294+
goto OUT_DECREF;
1295+
}
1296+
if (PyInt_Check(v)) {
1297+
ret = PyInt_AsLong(v);
1298+
goto OUT_DECREF;
1299+
}
12841300

12851301
OUT_DECREF:
12861302
Py_DECREF(v);

0 commit comments

Comments
 (0)