[libvirt PATCH v2] esx: generator: fix free of elements in lists
Martin Kletzander
mkletzan at redhat.com
Mon Sep 14 08:12:39 UTC 2020
On Thu, Sep 10, 2020 at 03:10:00PM +0200, Pino Toscano wrote:
>When a list is freed, we iterate through all the items, invoking the
>free function for each; the actual free function called for each element
>is the function of the actual type of each element, and thus the @_next
>pointer in the element struct has the same type as the element itself.
>Currently, the free function gets the parent of the current element
>type, and invoke its free function to continue freeing the list.
>However, in case the hierarchy of the classes has more than 1 level
>(i.e. Class <- SubClass <- SubSubClass), the invoked free function is
>only the parent class' one, and not the actual base class of the
>hierarchy.
>
>To fix that, change the generator to get the base class of a class, and
>invoking that instead. Also, avoid to set the @_next back, as it is not
>needed.
>
>Fixes commits 5cff36e39ae691fbd7c40597df1732eecf294150 and
>f76c6dde2e33233566e886d96e76b5fe0c102d9a.
>
>Signed-off-by: Pino Toscano <ptoscano at redhat.com>
Reviewed-by: Martin Kletzander <mkletzan at redhat.com>
>---
>Changes in v2:
>- ancestor -> base class
>
> scripts/esx_vi_generator.py | 26 +++++++++++++++++++++-----
> 1 file changed, 21 insertions(+), 5 deletions(-)
>
>diff --git a/scripts/esx_vi_generator.py b/scripts/esx_vi_generator.py
>index 863c8af964..e0782e35f3 100755
>--- a/scripts/esx_vi_generator.py
>+++ b/scripts/esx_vi_generator.py
>@@ -751,13 +751,13 @@ class Object(GenericObject):
> source += "{\n"
>
> if self.features & Object.FEATURE__LIST:
>- if self.extends is not None:
>+ base_class = get_base_class(self)
>+ if base_class:
> # avoid "dereferencing type-punned pointer will break
> # strict-aliasing rules" warnings
>- source += " esxVI_%s *next = (esxVI_%s *)item->_next;\n\n" \
>- % (self.extends, self.extends)
>- source += " esxVI_%s_Free(&next);\n" % self.extends
>- source += " item->_next = (esxVI_%s *)next;\n\n" % self.name
>+ source += " esxVI_%s *baseNext = (esxVI_%s *)item->_next;\n" \
>+ % (base_class, base_class)
>+ source += " esxVI_%s_Free(&baseNext);\n\n" % base_class
> else:
> source += " esxVI_%s_Free(&item->_next);\n\n" % self.name
>
>@@ -1250,6 +1250,21 @@ def is_known_type(type):
> type in enums_by_name)
>
>
>+def get_base_class(obj):
>+ if not obj.extends:
>+ return None
>+ base_class = None
>+ try:
>+ base_class = base_class_by_name[obj.extends]
>+ except KeyError:
>+ parent = objects_by_name[obj.extends]
>+ base_class = get_base_class(parent)
>+ if not base_class:
>+ base_class = parent.name
>+ base_class_by_name[name] = base_class
>+ return base_class
>+
>+
> def open_file(filename):
> return open(filename, "wt")
>
>@@ -1341,6 +1356,7 @@ managed_objects_by_name = {}
> enums_by_name = {}
> methods_by_name = {}
> block = None
>+base_class_by_name = {}
>
>
> # parse input file
>--
>2.26.2
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200914/065d3047/attachment-0001.sig>
More information about the libvir-list
mailing list