Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in
src/util/viralloc.h, define a new wrapper around an existing
cleanup function which will be called when a variable declared
with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant
viralloc.h include, since that has moved from the source module into
the header.
When variables of type virHashTablePtr are declared using
VIR_AUTOPTR, the function virHashFree will be run
automatically on it when it goes out of scope.
Signed-off-by: Sukrit Bhatnagar <skrtbhtngr(a)gmail.com>
Reviewed-by: Erik Skultety <eskultet(a)redhat.com>
---
src/util/virhash.c | 1 -
src/util/virhash.h | 4 ++++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/util/virhash.c b/src/util/virhash.c
index ecda55d..006ffd8 100644
--- a/src/util/virhash.c
+++ b/src/util/virhash.c
@@ -26,7 +26,6 @@
#include "virerror.h"
#include "virhash.h"
-#include "viralloc.h"
#include "virlog.h"
#include "virhashcode.h"
#include "virrandom.h"
diff --git a/src/util/virhash.h b/src/util/virhash.h
index 5b24fc0..dd789c6 100644
--- a/src/util/virhash.h
+++ b/src/util/virhash.h
@@ -16,6 +16,8 @@
# include <stdint.h>
# include <stdbool.h>
+# include "viralloc.h"
+
/*
* The hash table.
*/
@@ -200,4 +202,6 @@ void *virHashSearch(const virHashTable *table, virHashSearcher iter,
/* Convenience for when VIR_FREE(value) is sufficient as a data freer. */
void virHashValueFree(void *value, const void *name);
+VIR_DEFINE_AUTOPTR_FUNC(virHashTable, virHashFree)
+
#endif /* ! __VIR_HASH_H__ */
--
1.8.3.1