Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential memory leak in Parser/parser.c #101046

Closed
RuiliF opened this issue Jan 14, 2023 · 1 comment
Closed

Potential memory leak in Parser/parser.c #101046

RuiliF opened this issue Jan 14, 2023 · 1 comment
Labels
type-bug An unexpected behavior, bug, or error

Comments

@RuiliF
Copy link

RuiliF commented Jan 14, 2023

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

@pablogsal
Copy link
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.

pablogsal added a commit to pablogsal/cpython that referenced this issue Jan 16, 2023
pablogsal added a commit to pablogsal/cpython that referenced this issue Jan 16, 2023
…n raising MemoryError (pythonGH-101051).

(cherry picked from commit 1de4395)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit to pablogsal/cpython that referenced this issue Jan 16, 2023
…n raising MemoryError (pythonGH-101051).

(cherry picked from commit 1de4395)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit that referenced this issue Jan 16, 2023
…ing MemoryError (GH-101051). (#101086)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit that referenced this issue Jan 16, 2023
…ing MemoryError (GH-101051) (#101085)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants