Skip to content

Handle errors correctly in wait_helper in posixmodule.c #116404

@sobolevn

Description

@sobolevn

Bug report

There are several issues in this function:

  1. Our traditional case, when all errors are overwritten in a sequence preparation:

    cpython/Modules/posixmodule.c

    Lines 9584 to 9609 in d2f1b0e

    PyStructSequence_SET_ITEM(result, 0,
    PyFloat_FromDouble(doubletime(ru->ru_utime)));
    PyStructSequence_SET_ITEM(result, 1,
    PyFloat_FromDouble(doubletime(ru->ru_stime)));
    #define SET_INT(result, index, value)\
    PyStructSequence_SET_ITEM(result, index, PyLong_FromLong(value))
    SET_INT(result, 2, ru->ru_maxrss);
    SET_INT(result, 3, ru->ru_ixrss);
    SET_INT(result, 4, ru->ru_idrss);
    SET_INT(result, 5, ru->ru_isrss);
    SET_INT(result, 6, ru->ru_minflt);
    SET_INT(result, 7, ru->ru_majflt);
    SET_INT(result, 8, ru->ru_nswap);
    SET_INT(result, 9, ru->ru_inblock);
    SET_INT(result, 10, ru->ru_oublock);
    SET_INT(result, 11, ru->ru_msgsnd);
    SET_INT(result, 12, ru->ru_msgrcv);
    SET_INT(result, 13, ru->ru_nsignals);
    SET_INT(result, 14, ru->ru_nvcsw);
    SET_INT(result, 15, ru->ru_nivcsw);
    #undef SET_INT
    if (PyErr_Occurred()) {
    Py_DECREF(result);
    return NULL;
    }
  2. PyLong_FromPid can return NULL, but this case is ignored
    return Py_BuildValue("NiN", PyLong_FromPid(pid), status, result);

I have a PR ready.

Linked PRs

Metadata

Metadata

Assignees

Labels

extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions