[PATCH 05/10] util: alloc: Clean also stack'd data with VIR_AUTOCLEAN

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux