[Python-checkins] python/dist/src/Doc/ext run-func.c,1.3,1.4

nnorwitz@users.sourceforge.net nnorwitz@users.sourceforge.net
Mon, 16 Dec 2002 16:40:40 -0800


Update of /cvsroot/python/python/dist/src/Doc/ext
In directory sc8-pr-cvs1:/tmp/cvs-serv22479/Doc/ext

Modified Files:
	run-func.c 
Log Message:
Fix SF # 626275, missing DECREF's in embedding example

Tested w/valgrind, all paths except the return on PyInt_AsLong() failure
I think I got all of these right.

Backport candidate.


Index: run-func.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/ext/run-func.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** run-func.c	2 Dec 2002 04:40:21 -0000	1.3
--- run-func.c	17 Dec 2002 00:40:38 -0000	1.4
***************
*** 18,21 ****
--- 18,23 ----
  
      pModule = PyImport_Import(pName);
+     Py_DECREF(pName);
+ 
      if (pModule != NULL) {
          pDict = PyModule_GetDict(pModule);
***************
*** 30,33 ****
--- 32,37 ----
                  pValue = PyInt_FromLong(atoi(argv[i + 3]));
                  if (!pValue) {
+                     Py_DECREF(pArgs);
+                     Py_DECREF(pModule);
                      fprintf(stderr, "Cannot convert argument\n");
                      return 1;
***************
*** 37,40 ****
--- 41,45 ----
              }
              pValue = PyObject_CallObject(pFunc, pArgs);
+             Py_DECREF(pArgs);
              if (pValue != NULL) {
                  printf("Result of call: %ld\n", PyInt_AsLong(pValue));
***************
*** 42,54 ****
              }
              else {
                  PyErr_Print();
                  fprintf(stderr,"Call failed\n");
                  return 1;
              }
-             Py_DECREF(pArgs);
              /* pDict and pFunc are borrowed and must not be Py_DECREF-ed */
          }
          else {
!             PyErr_Print();
              fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
          }
--- 47,60 ----
              }
              else {
+                 Py_DECREF(pModule);
                  PyErr_Print();
                  fprintf(stderr,"Call failed\n");
                  return 1;
              }
              /* pDict and pFunc are borrowed and must not be Py_DECREF-ed */
          }
          else {
!             if (PyErr_Occurred())
!                 PyErr_Print();
              fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
          }
***************
*** 60,64 ****
          return 1;
      }
-     Py_DECREF(pName);
      Py_Finalize();
      return 0;
--- 66,69 ----