mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 11:49:12 +00:00 
			
		
		
		
	bpo-34170: Fix pymain_run_file() (GH-8660)
bpo-34170, bpo-34326: Fix pymain_run_file(): use PyRun_AnyFileExFlags(closeit=1) instead of calling fclose(fp) explicitly to close the input file before running the code.
This commit is contained in:
		
							parent
							
								
									46dc4e34ed
								
							
						
					
					
						commit
						d807862677
					
				
					 1 changed files with 6 additions and 6 deletions
				
			
		| 
						 | 
					@ -1129,14 +1129,16 @@ pymain_run_file(_PyMain *pymain, _PyCoreConfig *config, PyCompilerFlags *cf)
 | 
				
			||||||
                "%ls: '%ls' is a directory, cannot continue\n",
 | 
					                "%ls: '%ls' is a directory, cannot continue\n",
 | 
				
			||||||
                config->program, filename);
 | 
					                config->program, filename);
 | 
				
			||||||
        pymain->status = 1;
 | 
					        pymain->status = 1;
 | 
				
			||||||
        goto done;
 | 
					        fclose(fp);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* call pending calls like signal handlers (SIGINT) */
 | 
					    /* call pending calls like signal handlers (SIGINT) */
 | 
				
			||||||
    if (Py_MakePendingCalls() == -1) {
 | 
					    if (Py_MakePendingCalls() == -1) {
 | 
				
			||||||
        PyErr_Print();
 | 
					        PyErr_Print();
 | 
				
			||||||
        pymain->status = 1;
 | 
					        pymain->status = 1;
 | 
				
			||||||
        goto done;
 | 
					        fclose(fp);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    PyObject *unicode, *bytes = NULL;
 | 
					    PyObject *unicode, *bytes = NULL;
 | 
				
			||||||
| 
						 | 
					@ -1155,12 +1157,10 @@ pymain_run_file(_PyMain *pymain, _PyCoreConfig *config, PyCompilerFlags *cf)
 | 
				
			||||||
        filename_str = "<filename encoding error>";
 | 
					        filename_str = "<filename encoding error>";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int run = PyRun_AnyFileExFlags(fp, filename_str, 0, cf);
 | 
					    /* PyRun_AnyFileExFlags(closeit=1) calls fclose(fp) before running code */
 | 
				
			||||||
 | 
					    int run = PyRun_AnyFileExFlags(fp, filename_str, 1, cf);
 | 
				
			||||||
    Py_XDECREF(bytes);
 | 
					    Py_XDECREF(bytes);
 | 
				
			||||||
    pymain->status = (run != 0);
 | 
					    pymain->status = (run != 0);
 | 
				
			||||||
 | 
					 | 
				
			||||||
done:
 | 
					 | 
				
			||||||
    fclose(fp);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue