From 7b03fa0b8f9454893c1f995fc8605bba97968b50 Mon Sep 17 00:00:00 2001 From: ashnaaseth2325-oss Date: Sat, 28 Mar 2026 12:48:34 +0000 Subject: [PATCH 1/3] util: use context managers in genMetrics.py to fix fd leaks Replace bare open()/close() calls in read_sdc() and merge_jsons() with context managers so file descriptors are released on exception. Signed-off-by: Ashnaa Seth Signed-off-by: ashnaaseth2325-oss --- flow/util/genMetrics.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/flow/util/genMetrics.py b/flow/util/genMetrics.py index 938a4c91fb..62c8b6dc33 100755 --- a/flow/util/genMetrics.py +++ b/flow/util/genMetrics.py @@ -142,17 +142,14 @@ def extractGnuTime(prefix, jsonFile, file): # def read_sdc(file_name): clkList = [] - sdcFile = None try: - sdcFile = open(file_name, "r") + with open(file_name, "r") as sdcFile: + lines = sdcFile.readlines() except IOError: print("[WARN] Failed to open file:", file_name) return clkList - lines = sdcFile.readlines() - sdcFile.close() - for line in lines: if len(line.split()) < 2: continue @@ -185,10 +182,9 @@ def is_git_repo(folder=None): def merge_jsons(root_path, output, files): paths = sorted(glob(os.path.join(root_path, files))) for path in paths: - file = open(path, "r") - data = json.load(file) + with open(path, "r") as file: + data = json.load(file) output.update(data) - file.close() def extract_metrics( From 75af8d6a651572ed0759714e796f68ca3c6e91b1 Mon Sep 17 00:00:00 2001 From: ashnaaseth2325-oss Date: Sat, 28 Mar 2026 23:20:08 +0530 Subject: [PATCH 2/3] Update flow/util/genMetrics.py Co-authored-by: Matt Liberty Signed-off-by: ashnaaseth2325-oss --- flow/util/genMetrics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flow/util/genMetrics.py b/flow/util/genMetrics.py index 62c8b6dc33..77bd9891a5 100755 --- a/flow/util/genMetrics.py +++ b/flow/util/genMetrics.py @@ -146,8 +146,8 @@ def read_sdc(file_name): try: with open(file_name, "r") as sdcFile: lines = sdcFile.readlines() - except IOError: - print("[WARN] Failed to open file:", file_name) +except IOError as e: + print(f"[WARN] Failed to open file: {file_name} ({e.strerror})") return clkList for line in lines: From 9f313aa8b1aaa6f7d6c4d73255e90bda7d6891a7 Mon Sep 17 00:00:00 2001 From: Ashnaa Seth Date: Sat, 28 Mar 2026 18:20:34 +0000 Subject: [PATCH 3/3] fix: correct f-string syntax Signed-off-by: Ashnaa Seth --- flow/util/genMetrics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flow/util/genMetrics.py b/flow/util/genMetrics.py index 77bd9891a5..e112cd1d2d 100755 --- a/flow/util/genMetrics.py +++ b/flow/util/genMetrics.py @@ -146,8 +146,8 @@ def read_sdc(file_name): try: with open(file_name, "r") as sdcFile: lines = sdcFile.readlines() -except IOError as e: - print(f"[WARN] Failed to open file: {file_name} ({e.strerror})") + except OSError as e: + print(f"[WARN] Failed to open file: {file_name} ({e})") return clkList for line in lines: