Skip to content

Logic bug in new_threadstate() error path, interp is NULL #155504

Description

@nascheme

Bug report

Bug description:

On allocation failure, interp == NULL and that confuses free_threadstate(). Possible fix is to set interp inside alloc_threadstate().

Reproducer, insert after the alloc_threadstate() call:

      _PyThreadStateImpl *tstate = alloc_threadstate(interp);
      if (tstate == NULL) {
          return NULL;
      }
      if (getenv("PY_TSTATE_FAIL_INJECT")) {
          fprintf(stderr, "INJECT: tstate=%p interp=%p base.interp=%p\n",
                  (void *)tstate, (void *)interp, (void *)tstate->base.interp);
          free_threadstate(tstate);
          return NULL;
      }

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions