From 0c5e7435ca9db2b564ac7a545c59ac09558c9f16 Mon Sep 17 00:00:00 2001 From: Sukrit Bhatnagar Date: Tue, 24 Jul 2018 21:22:07 +0530 Subject: [PATCH] util: hash: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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 Reviewed-by: Erik Skultety --- 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 ecda55dba5..006ffd8d7f 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 5b24fc0006..dd789c6e51 100644 --- a/src/util/virhash.h +++ b/src/util/virhash.h @@ -16,6 +16,8 @@ # include # include +# 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__ */ -- GitLab