1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-21 20:23:50 +03:00

gp: Fix resource leaks

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Joseph Sutton
2023-08-29 16:29:55 +12:00
committed by Andrew Bartlett
parent 928f2bbc6b
commit 34042677b7
6 changed files with 38 additions and 13 deletions

View File

@@ -23,7 +23,11 @@ class gp_msgs_ext(gp_pol_ext, gp_misc_applier):
raise ValueError('"%s" is not a message attribute' % attribute)
data = self.parse_value(value)
mfile = os.path.join(cdir, attribute)
current = open(mfile, 'r').read() if os.path.exists(mfile) else ''
if os.path.exists(mfile):
with open(mfile, 'r') as f:
current = f.read()
else:
current = ''
# Only overwrite the msg if it hasn't been modified. It may have been
# modified by another GPO.
if 'new_val' not in data or current.strip() == data['new_val'].strip():
@@ -44,7 +48,8 @@ class gp_msgs_ext(gp_pol_ext, gp_misc_applier):
e.valuename)
mfile = os.path.join(cdir, e.valuename)
if os.path.exists(mfile):
old_val = open(mfile, 'r').read()
with open(mfile, 'r') as f:
old_val = f.read()
else:
old_val = ''
# If policy is already applied, skip application