]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: alloc: Note that VIR_AUTOPTR/VIR_AUTOCLEAN must not be used with vectors
authorPeter Krempa <pkrempa@redhat.com>
Fri, 22 Feb 2019 15:32:11 +0000 (16:32 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 4 Mar 2019 12:04:20 +0000 (13:04 +0100)
We'd free only the first element of the vector leaking the rest.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/util/viralloc.h

index 15451d467384d9674160c0694c90994ab6c011bb..518419e694aa5f2c7f3ebf35c8a89e489e3d7dd7 100644 (file)
@@ -650,6 +650,9 @@ void virAllocTestHook(void (*func)(int, void*), void *data);
  * the variable declared with it by calling the function
  * defined by VIR_DEFINE_AUTOPTR_FUNC when the variable
  * goes out of scope.
+ *
+ * Note that this macro must NOT be used with vectors! The freeing function
+ * will not free any elements beyond the first.
  */
 # define VIR_AUTOPTR(type) \
     __attribute__((cleanup(VIR_AUTOPTR_FUNC_NAME(type)))) type *
@@ -662,6 +665,9 @@ void virAllocTestHook(void (*func)(int, void*), void *data);
  * when the variable goes out of scope.
  * The cleanup function is registered by VIR_DEFINE_AUTOCLEAN_FUNC macro for
  * the given type.
+ *
+ * Note that this macro must NOT be used with vectors! The cleaning function
+ * will not clean any elements beyond the first.
  */
 # define VIR_AUTOCLEAN(type) \
     __attribute__((cleanup(VIR_AUTOCLEAN_FUNC_NAME(type)))) type