card: fix memory leak from nested function scoping (#33328)

* stash

* no other leaks! pm.send grows memory usage by ~20mb but that's it

* undo

* clean up
pull/33329/head
Shane Smiskol 9 months ago committed by GitHub
parent 08f64ae30a
commit ee9977df2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 17
      selfdrive/car/card.py

@ -66,14 +66,6 @@ def is_dataclass(obj):
return hasattr(obj, _FIELDS)
def asdictref(obj) -> dict[str, Any]:
"""
Similar to dataclasses.asdict without recursive type checking and copy.deepcopy
Note that the resulting dict will contain references to the original struct as a result
"""
if not is_dataclass(obj):
raise TypeError("asdictref() should be called on dataclass instances")
def _asdictref_inner(obj) -> dict[str, Any] | Any:
if is_dataclass(obj):
ret = {}
@ -85,6 +77,15 @@ def asdictref(obj) -> dict[str, Any]:
else:
return obj
def asdictref(obj) -> dict[str, Any]:
"""
Similar to dataclasses.asdict without recursive type checking and copy.deepcopy
Note that the resulting dict will contain references to the original struct as a result
"""
if not is_dataclass(obj):
raise TypeError("asdictref() should be called on dataclass instances")
return _asdictref_inner(obj)

Loading…
Cancel
Save