Skip to content

Commit 31b7d4f

Browse files
committed
INTEGRITY: Remove global database connection object from fileset.py, which is never closed.
1 parent 074da92 commit 31b7d4f

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

fileset.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,6 @@
3232

3333
secret_key = os.urandom(24)
3434

35-
base_dir = os.path.dirname(os.path.abspath(__file__))
36-
config_path = os.path.join(base_dir, "mysql_config.json")
37-
with open(config_path) as f:
38-
mysql_cred = json.load(f)
39-
40-
conn = pymysql.connect(
41-
host=mysql_cred["servername"],
42-
user=mysql_cred["username"],
43-
password=mysql_cred["password"],
44-
db=mysql_cred["dbname"],
45-
charset="utf8mb4",
46-
cursorclass=pymysql.cursors.DictCursor,
47-
autocommit=False,
48-
)
49-
5035

5136
@app.route("/")
5237
def index():
@@ -348,7 +333,7 @@ def fileset():
348333
html += "<th>Description</th>\n"
349334
html += "<th>Log Text</th>\n"
350335

351-
related_filesets = get_all_related_filesets(id, conn)
336+
related_filesets = get_all_related_filesets(id, connection)
352337

353338
cursor.execute(
354339
f"SELECT * FROM history WHERE fileset IN ({','.join(map(str, related_filesets))}) OR oldfileset IN ({','.join(map(str, related_filesets))})"
@@ -971,9 +956,12 @@ def validate():
971956
del json_response["files"]
972957
json_response["status"] = "no_metadata"
973958

974-
fileset_id = user_insert_fileset(json_object, ip, conn)
959+
conn = db_connect()
960+
try:
961+
fileset_id = user_insert_fileset(json_object, ip, conn)
962+
finally:
963+
conn.close()
975964
json_response["fileset"] = fileset_id
976-
print(f"Response: {json_response}")
977965
return jsonify(json_response)
978966

979967
matched_map = {}

0 commit comments

Comments
 (0)