]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:scripting: Ensure generated error definition files are closed after use
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Wed, 10 Jan 2024 22:23:53 +0000 (11:23 +1300)
committerJoseph Sutton <jsutton@samba.org>
Mon, 15 Jan 2024 00:48:40 +0000 (00:48 +0000)
This helps to avoid warnings like this one:

/data/samba/source4/scripting/bin/gen_hresult.py:178: ResourceWarning: unclosed file <_io.TextIOWrapper name='/data/samba/bin/default/libcli/util/hresult.c' mode='w' encoding='UTF-8'>
  main()
ResourceWarning: Enable tracemalloc to get the object allocation traceback

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
source4/scripting/bin/gen_hresult.py

index b302d2d3dc8cc081f8082cec215e9471ca444637..03d25c820ffd7cdce3eea0eb69134e3fa0e986f5 100755 (executable)
@@ -168,11 +168,10 @@ def main ():
     with open(input_file1) as file_contents:
         errors = parseErrorDescriptions(file_contents, False, transformErrorName)
 
-    out_file = open(headerfile_name,"w")
-    generateHeaderFile(out_file, errors)
-    out_file.close()
-    out_file = open(sourcefile_name,"w")
-    generateSourceFile(out_file, errors)
+    with open(headerfile_name,"w") as out_file:
+        generateHeaderFile(out_file, errors)
+    with open(sourcefile_name,"w") as out_file:
+        generateSourceFile(out_file, errors)
 
 if __name__ == '__main__':