diff --git a/libraries/libapparmor/swig/SWIG/libapparmor.i b/libraries/libapparmor/swig/SWIG/libapparmor.i index f982900fd..09208fd32 100644 --- a/libraries/libapparmor/swig/SWIG/libapparmor.i +++ b/libraries/libapparmor/swig/SWIG/libapparmor.i @@ -8,6 +8,26 @@ %} %include "typemaps.i" + +%newobject parse_record; +%delobject free_record; +/* + * Despite its name, %delobject does not hook up destructors to language + * deletion mechanisms. Instead, it sets flags so that manually calling the + * free function and then deleting by language mechanisms doesn't cause a + * double-free. (Manually calling the free function twice can still cause a + * double-free.) + * + * Instead, we need manually extend the struct with a C++-like destructor. + * This ensures that the record struct is free when the high-level object + * goes out of scope. + */ +%extend aa_log_record { + ~aa_log_record() { + free_record($self); + } +} + %include /** diff --git a/libraries/libapparmor/swig/python/test/test_python.py.in b/libraries/libapparmor/swig/python/test/test_python.py.in index 54a1e4f05..95912ccd0 100644 --- a/libraries/libapparmor/swig/python/test/test_python.py.in +++ b/libraries/libapparmor/swig/python/test/test_python.py.in @@ -118,6 +118,9 @@ class AAPythonBindingsTests(unittest.TestCase): # FIXME: out files should report log version? # FIXME: or can we just deprecate v1 logs? continue + elif key == "thisown": + # SWIG generates this key to track memory allocation + continue elif key in NO_VALUE_MAP: if NO_VALUE_MAP[key] == value: continue