mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-22 10:07:12 +00:00
Annotate SWIG aa_log_record alloc+dealloc
Swig generates a "thisown" attribute, which is an escape hatch in case higher-level code does something weird and needs to tell SWIG whether to free the C object when Python garbage collects it. Adding this attribute is not a breaking change w.r.t access to the other attributes of the parsed record. Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
This commit is contained in:
parent
436ebda9b5
commit
e5fd0fc636
@ -8,6 +8,26 @@
|
|||||||
%}
|
%}
|
||||||
|
|
||||||
%include "typemaps.i"
|
%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 <aalogparse.h>
|
%include <aalogparse.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,6 +118,9 @@ class AAPythonBindingsTests(unittest.TestCase):
|
|||||||
# FIXME: out files should report log version?
|
# FIXME: out files should report log version?
|
||||||
# FIXME: or can we just deprecate v1 logs?
|
# FIXME: or can we just deprecate v1 logs?
|
||||||
continue
|
continue
|
||||||
|
elif key == "thisown":
|
||||||
|
# SWIG generates this key to track memory allocation
|
||||||
|
continue
|
||||||
elif key in NO_VALUE_MAP:
|
elif key in NO_VALUE_MAP:
|
||||||
if NO_VALUE_MAP[key] == value:
|
if NO_VALUE_MAP[key] == value:
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user