[Python-checkins] CVS: python/dist/src/Modules parsermodule.c,2.66,2.67

Fred L. Drake fdrake@users.sourceforge.net
Wed, 05 Dec 2001 14:10:47 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv23435

Modified Files:
	parsermodule.c 
Log Message:
Fix memory leak in the parser module:  There were two leaks in
parser_tuple2st() and a failure to propogate an error in
build_node_children() (masking yet another leak, of course!).
This closes SF bug #485133 (confirmed by Insure++).


Index: parsermodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/parsermodule.c,v
retrieving revision 2.66
retrieving revision 2.67
diff -C2 -d -r2.66 -r2.67
*** parsermodule.c	2001/10/15 15:44:05	2.66
--- parsermodule.c	2001/12/05 22:10:44	2.67
***************
*** 29,32 ****
--- 29,33 ----
  #include "graminit.h"                   /* symbols defined in the grammar */
  #include "node.h"                       /* internal parser structure      */
+ #include "errcode.h"                    /* error codes for PyNode_*()     */
  #include "token.h"                      /* token definitions              */
                                          /* ISTERMINAL() / ISNONTERMINAL() */
***************
*** 599,602 ****
--- 600,605 ----
              if (validate_expr_tree(tree))
                  st = parser_newstobject(tree, PyST_EXPR);
+             else
+                 PyNode_Free(tree);
          }
          else if (start_sym == file_input) {
***************
*** 604,607 ****
--- 607,612 ----
              if (validate_file_input(tree))
                  st = parser_newstobject(tree, PyST_SUITE);
+             else
+                 PyNode_Free(tree);
          }
          else {
***************
*** 633,637 ****
  {
      int len = PyObject_Size(tuple);
!     int i;
  
      for (i = 1; i < len; ++i) {
--- 638,642 ----
  {
      int len = PyObject_Size(tuple);
!     int i, err;
  
      for (i = 1; i < len; ++i) {
***************
*** 714,718 ****
              return (0);
          }
!         PyNode_AddChild(root, type, strn, *line_num);
  
          if (ISNONTERMINAL(type)) {
--- 719,733 ----
              return (0);
          }
!         err = PyNode_AddChild(root, type, strn, *line_num);
!         if (err == E_NOMEM) {
!             PyMem_DEL(strn);
!             return (node *) PyErr_NoMemory();
!         }
!         if (err == E_OVERFLOW) {
!             PyMem_DEL(strn);
!             PyErr_SetString(PyExc_ValueError,
!                             "unsupported number of child nodes");
!             return NULL;
!         }
  
          if (ISNONTERMINAL(type)) {
***************
*** 759,765 ****
  
          res = PyNode_New(num);
!         if (res != build_node_children(tuple, res, &line_num)) {
!             PyNode_Free(res);
!             res = 0;
          }
      }
--- 774,782 ----
  
          res = PyNode_New(num);
!         if (res != NULL) {
!             if (res != build_node_children(tuple, res, &line_num)) {
!                 PyNode_Free(res);
!                 res = NULL;
!             }
          }
      }