From 51eb35b0cce04ce79cc530375b75d300ff55f818 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20De=20Keersmaeker?=
 <francois.dekeersmaeker@uclouvain.be>
Date: Mon, 12 May 2025 09:56:04 +0200
Subject: [PATCH] Memory: free files

---
 dns_unbound_cache_reader/dns_unbound_cache_reader.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/dns_unbound_cache_reader/dns_unbound_cache_reader.py b/dns_unbound_cache_reader/dns_unbound_cache_reader.py
index a7bdbcf..3d7056a 100644
--- a/dns_unbound_cache_reader/dns_unbound_cache_reader.py
+++ b/dns_unbound_cache_reader/dns_unbound_cache_reader.py
@@ -79,8 +79,9 @@ def update_dns_table(
 
         if host in localhost:
             ## Unbound runs on localhost
-            proc = subprocess.run(cmd.split(), capture_output=True)
-            dns_cache = proc.stdout.decode().strip().split("\n")
+            proc = subprocess.run(cmd.split(), capture_output=True, text=True)
+            dns_cache = proc.stdout.strip().split("\n")
+            del proc
 
         else:
             ## Unbound runs on a remote host
@@ -90,6 +91,9 @@ def update_dns_table(
             # Get the DNS cache
             result = remote.run(cmd)
             dns_cache = result.stdout.strip().split("\n")
+            # Free resources
+            del remote
+            del result
 
     else:
         # Read DNS cache from file
-- 
GitLab