> Use function attributes to catch cases where hash table is allocated
> but not freed correctly.
>
> Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
> ---
> lib/hash/rte_fbk_hash.h | 24 +++++++++++++-----------
> lib/hash/rte_hash.h | 21 +++++++++++----------
> 2 files changed, 24 insertions(+), 21 deletions(-)
>
> diff --git a/lib/hash/rte_fbk_hash.h b/lib/hash/rte_fbk_hash.h
> index 1f0c1d1b6c..b1a43f37b4 100644
> --- a/lib/hash/rte_fbk_hash.h
> +++ b/lib/hash/rte_fbk_hash.h
> @@ -322,6 +322,16 @@ rte_fbk_hash_get_load_factor(struct rte_fbk_hash_table
> *ht)
> */
> struct rte_fbk_hash_table *rte_fbk_hash_find_existing(const char *name);
>
> +
> +/**
> + * Free all memory used by a hash table.
> + * Has no effect on hash tables allocated in memory zones
> + *
> + * @param ht
> + * Hash table to deallocate.
> + */
> +void rte_fbk_hash_free(struct rte_fbk_hash_table *ht);
> +
> /**
> * Create a new hash table for use with four byte keys.
> *
> @@ -339,17 +349,9 @@ struct rte_fbk_hash_table
> *rte_fbk_hash_find_existing(const char *name);
> * - EEXIST - a memzone with the same name already exists
> * - ENOMEM - no appropriate memory area found in which to create memzone
> */
> -struct rte_fbk_hash_table * \
> -rte_fbk_hash_create(const struct rte_fbk_hash_params *params);
> -
> -/**
> - * Free all memory used by a hash table.
> - * Has no effect on hash tables allocated in memory zones
> - *
> - * @param ht
> - * Hash table to deallocate.
> - */
> -void rte_fbk_hash_free(struct rte_fbk_hash_table *ht);
> +struct rte_fbk_hash_table *
> +rte_fbk_hash_create(const struct rte_fbk_hash_params *params)
> + __rte_malloc __rte_dealloc(rte_fbk_hash_free, 1);
>
> #ifdef __cplusplus
> }
> diff --git a/lib/hash/rte_hash.h b/lib/hash/rte_hash.h
> index 05ab447e4a..736fb15885 100644
> --- a/lib/hash/rte_hash.h
> +++ b/lib/hash/rte_hash.h
> @@ -125,6 +125,15 @@ struct rte_hash_rcu_config {
> /** @internal A hash table structure. */
> struct rte_hash;
>
> +/**
> + * De-allocate all memory used by hash table.
> + *
> + * @param h
> + * Hash table to free, if NULL, the function does nothing.
> + */
> +void
> +rte_hash_free(struct rte_hash *h);
> +
> /**
> * Create a new hash table.
> *
> @@ -143,7 +152,8 @@ struct rte_hash;
> * - ENOMEM - no appropriate memory area found in which to create memzone
> */
> struct rte_hash *
> -rte_hash_create(const struct rte_hash_parameters *params);
> +rte_hash_create(const struct rte_hash_parameters *params)
> + __rte_malloc __rte_dealloc(rte_hash_free, 1);
>
> /**
> * Set a new hash compare function other than the default one.
> @@ -171,15 +181,6 @@ void rte_hash_set_cmp_func(struct rte_hash *h,
> rte_hash_cmp_eq_t func);
> struct rte_hash *
> rte_hash_find_existing(const char *name);
>
> -/**
> - * De-allocate all memory used by hash table.
> - *
> - * @param h
> - * Hash table to free, if NULL, the function does nothing.
> - */
> -void
> -rte_hash_free(struct rte_hash *h);
> -
> /**
> * Reset all hash structure, by zeroing all entries.
> * When RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF is enabled,
> --
Acked-by: Konstantin Ananyev <konstantin.anan...@huawei.com>
> 2.45.2