Summary
Severity: Critical
File: sdk/basyx/aas/adapter/aasx.py:861-917
Description
_store_refcount is designed to track how many _name_map entries reference the same content hash, so delete_file() can free the underlying bytes only when the last reference is removed. The refcount is never incremented, so files are never freed.
# add_file():
if hash not in self._store:
self._store[hash] = data
self._store_refcount[hash] = 0 # initialized to 0
# _assign_unique_name():
self._name_map[new_name] = (sha, content_type)
return new_name # refcount NEVER incremented
# delete_file():
self._store_refcount[hash] -= 1 # 0 → -1
if self._store_refcount[hash] == 0: # -1 != 0, always False
del self._store[hash] # NEVER executed
del self._store_refcount[hash] # NEVER executed
del self._name_map[name]
Because _assign_unique_name() never increments _store_refcount, the count stays at 0 after any add_file(). Every delete_file() decrements to -1 and the equality check == 0 is never true, so _store[hash] and _store_refcount[hash] are never cleaned up. Every file ever added leaks indefinitely.
Fix
Increment _store_refcount[sha] += 1 inside _assign_unique_name() when a new _name_map entry is created (the first branch of the while True loop). Also decrement it (and skip the increment) inside the second branch when a duplicate name already maps to the same hash.
Summary
Severity: Critical
File:
sdk/basyx/aas/adapter/aasx.py:861-917Description
_store_refcountis designed to track how many_name_mapentries reference the same content hash, sodelete_file()can free the underlying bytes only when the last reference is removed. The refcount is never incremented, so files are never freed.Because
_assign_unique_name()never increments_store_refcount, the count stays at 0 after anyadd_file(). Everydelete_file()decrements to -1 and the equality check== 0is never true, so_store[hash]and_store_refcount[hash]are never cleaned up. Every file ever added leaks indefinitely.Fix
Increment
_store_refcount[sha] += 1inside_assign_unique_name()when a new_name_mapentry is created (the first branch of thewhile Trueloop). Also decrement it (and skip the increment) inside the second branch when a duplicate name already maps to the same hash.