Module: check_mk
Branch: master
Commit: c9f4fe781e5e8c7e742f943b6ca04d1ffda37850
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c9f4fe781e5e8c…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Mon Oct 29 15:01:16 2018 +0100
6672 FIX Fixed possible file handle leak on ipaddress lookup
Change-Id: I0a4e20388b88eae0a7040169610a8ff035abf9d1
---
.werks/6672 | 10 ++++++++++
cmk_base/ip_lookup.py | 22 +++++++++++++---------
2 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/.werks/6672 b/.werks/6672
new file mode 100644
index 0000000..dfe48c5
--- /dev/null
+++ b/.werks/6672
@@ -0,0 +1,10 @@
+Title: Fixed possible file handle leak on ipaddress lookup
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1540821637
+Class: fix
+
+
diff --git a/cmk_base/ip_lookup.py b/cmk_base/ip_lookup.py
index 0052488..4b33349 100644
--- a/cmk_base/ip_lookup.py
+++ b/cmk_base/ip_lookup.py
@@ -188,19 +188,23 @@ def _update_ip_lookup_cache(cache_id, ipa):
# Read already known data
cache_path = cmk.paths.var_dir + '/ipaddresses.cache'
- data_from_file = cmk.store.load_data_from_file(cache_path, default={}, lock=True)
+ try:
+ data_from_file = cmk.store.load_data_from_file(cache_path, default={},
lock=True)
- _convert_legacy_ip_lookup_cache(data_from_file)
- ip_lookup_cache.update(data_from_file)
- ip_lookup_cache[cache_id] = ipa
+ _convert_legacy_ip_lookup_cache(data_from_file)
+ ip_lookup_cache.update(data_from_file)
+ ip_lookup_cache[cache_id] = ipa
- # (I don't like this)
- # TODO: this file always grows... there should be a cleanup mechanism
- # maybe on "cmk --update-dns-cache"
- # The cache_path is already locked from a previous function call..
- cmk.store.save_data_to_file(cache_path, ip_lookup_cache)
+ # (I don't like this)
+ # TODO: this file always grows... there should be a cleanup mechanism
+ # maybe on "cmk --update-dns-cache"
+ # The cache_path is already locked from a previous function call..
+ cmk.store.save_data_to_file(cache_path, ip_lookup_cache)
+ finally:
+ cmk.store.release_lock(cache_path)
+# TODO: remove unused code?
def _write_ip_lookup_cache():
ip_lookup_cache = cmk_base.config_cache.get_dict("ip_lookup")