Skip to content

Potential memory leak in Parser/parser.c #101046

Description

@RuiliF

Bug report

In Parse/parse.c, function _loop0_1_rule (line 23809), object _children

  if (_n == _children_capacity) {
      _children_capacity *= 2;
      void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *));
      if (!_new_children) {
          p->error_indicator = 1;
          PyErr_NoMemory();
          p->level--;
          return NULL; 
      }     
      _children = _new_children;
  }     

If PyMem_Realloc fails, the original object will be kept untouched. Thus returning NULL without free'ing _children will cause a memory leak.

Your environment

Python 3.12

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Jan 14, 2023
  2. added a commit that references this issue on Jan 15, 2023
  3. pablogsal commented on Jan 15, 2023

    @pablogsal
    Member

    Thanks for opening the issue @RuiliF, unfortunate #101049 just changes a single rule while all rules are subjected to this. I have created a PR fixing this correctly in #101051.

  4. added 6 commits that reference this issue on Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions