mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 07:57:27 +03:00 
			
		
		
		
	Close exclusive fp on open exception
This commit is contained in:
		
							parent
							
								
									3d76a686c4
								
							
						
					
					
						commit
						747eccbfc2
					
				|  | @ -17,12 +17,16 @@ class TestBmpReference(PillowTestCase): | ||||||
|         """ These shouldn't crash/dos, but they shouldn't return anything |         """ These shouldn't crash/dos, but they shouldn't return anything | ||||||
|         either """ |         either """ | ||||||
|         for f in self.get_files('b'): |         for f in self.get_files('b'): | ||||||
|  |             def open(f): | ||||||
|                 try: |                 try: | ||||||
|                     im = Image.open(f) |                     im = Image.open(f) | ||||||
|                     im.load() |                     im.load() | ||||||
|                 except Exception:  # as msg: |                 except Exception:  # as msg: | ||||||
|                     pass |                     pass | ||||||
| 
 | 
 | ||||||
|  |             # Assert that there is no unclosed file warning | ||||||
|  |             self.assert_warning(None, open, f) | ||||||
|  | 
 | ||||||
|     def test_questionable(self): |     def test_questionable(self): | ||||||
|         """ These shouldn't crash/dos, but it's not well defined that these |         """ These shouldn't crash/dos, but it's not well defined that these | ||||||
|         are in spec """ |         are in spec """ | ||||||
|  |  | ||||||
|  | @ -2641,6 +2641,10 @@ def open(fp, mode="r"): | ||||||
|                 # opening failures that are entirely expected. |                 # opening failures that are entirely expected. | ||||||
|                 # logger.debug("", exc_info=True) |                 # logger.debug("", exc_info=True) | ||||||
|                 continue |                 continue | ||||||
|  |             except Exception: | ||||||
|  |                 if exclusive_fp: | ||||||
|  |                     fp.close() | ||||||
|  |                 raise | ||||||
|         return None |         return None | ||||||
| 
 | 
 | ||||||
|     im = _open_core(fp, filename, prefix) |     im = _open_core(fp, filename, prefix) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user