Allocated resources are not released properly. This can slow down or crash your system. They must be closed along all paths to prevent a resource leak.
1def read_file_noncompliant(filename): 2 file = open(filename, 'r') 3 # Noncompliant: method returns without properly closing the file. 4 return file.readlines()
1def read_file_compliant(filename): 2 # Compliant: file is declared using a `with` statement. 3 with open(filename, 'r') as file: 4 return f.readlines()