[PATCH weston 5/9] compositor-drm: drm_property_info_free() must reset
Pekka Paalanen
ppaalanen at gmail.com
Fri Feb 9 13:07:23 UTC 2018
From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
This function needs to reset the structures to NULL, otherwise it is not
possible to re-use a once "freed" property info array.
Being able to re-use an array is useful when the memory allocation and
array lifetimes do not match. A specific example is drm_output that is
changed to allocate the CRTC on enable() and deallocate it on disable().
A drm_output might be enabled and disabled multiple times.
Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
libweston/compositor-drm.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index 4b505707..23ffb005 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -721,7 +721,9 @@ drm_property_info_populate(struct drm_backend *b,
/**
* Free DRM property information
*
- * Frees all memory associated with a DRM property info array.
+ * Frees all memory associated with a DRM property info array and zeroes
+ * it out, leaving it usable for a further drm_property_info_update() or
+ * drm_property_info_free().
*
* @param info DRM property info array
* @param num_props Number of entries in array to free
@@ -733,6 +735,8 @@ drm_property_info_free(struct drm_property_info *info, int num_props)
for (i = 0; i < num_props; i++)
free(info[i].enum_values);
+
+ memset(info, 0, sizeof(*info) * num_props);
}
static void
--
2.13.6
More information about the wayland-devel
mailing list