VIR_AUTOCLEAN uses __attribute__(cleanup) to clean stack'd data types.
The implementation calls the callback but did not clean the stack'd
structure besides to what the called function did. This adds a memset
call to clean it when unrolling the stack to achieve the same stack
cleanlines as with VIR_AUTOFREE and VIR_AUTOPTR.
The change from inline to ATTRIBUTE_UNUSED is necessary as gcc was
moaning that inlining would sometimes increase code size.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
cfg.mk | 2 +-
src/util/viralloc.h | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index a62d4db13b..932cdb8664 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1306,7 +1306,7 @@ exclude_file_name_regexp--sc_prohibit_getenv = \
^tests/.*\.[ch]$$
exclude_file_name_regexp--sc_avoid_attribute_unused_in_header = \
- ^(src/util/virlog\.h|src/network/bridge_driver\.h)$$
+ ^(src/util/virlog\.h|src/network/bridge_driver\.h|src/util/viralloc\.h)$$
exclude_file_name_regexp--sc_prohibit_mixed_case_abbreviations = \
^src/(vbox/vbox_CAPI.*.h|esx/esx_vi.(c|h)|esx/esx_storage_backend_iscsi.c)$$
diff --git a/src/util/viralloc.h b/src/util/viralloc.h
index a1708b772c..c8133938bf 100644
--- a/src/util/viralloc.h
+++ b/src/util/viralloc.h
@@ -637,9 +637,10 @@ void virAllocTestHook(void (*func)(int, void*), void *data);
* take pointer to @type.
*/
# define VIR_DEFINE_AUTOCLEAN_FUNC(type, func) \
- static inline void VIR_AUTOCLEAN_FUNC_NAME(type)(type *_ptr) \
+ static void ATTRIBUTE_UNUSED VIR_AUTOCLEAN_FUNC_NAME(type)(type *_ptr) \
{ \
(func)(_ptr); \
+ memset(_ptr, 0, sizeof(*_ptr));\
}
/**
--
2.20.1