[PATCH v6 06/15] bitratestats: add allocation function attributes
Stephen Hemminger
stephen at networkplumber.org
Sat Jan 25 19:36:40 CET 2025
Use function attributes to catch cases where bitratestats is allocated
but not freed correctly.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
lib/bitratestats/rte_bitrate.h | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/lib/bitratestats/rte_bitrate.h b/lib/bitratestats/rte_bitrate.h
index 979a712837..75883f8779 100644
--- a/lib/bitratestats/rte_bitrate.h
+++ b/lib/bitratestats/rte_bitrate.h
@@ -7,6 +7,8 @@
#include <stdint.h>
+#include <rte_common.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -17,16 +19,6 @@ extern "C" {
*/
struct rte_stats_bitrates;
-
-/**
- * Allocate a bitrate statistics structure
- *
- * @return
- * - Pointer to structure on success
- * - NULL on error (zmalloc failure)
- */
-struct rte_stats_bitrates *rte_stats_bitrate_create(void);
-
/**
* Free bitrate statistics structure
*
@@ -36,6 +28,16 @@ struct rte_stats_bitrates *rte_stats_bitrate_create(void);
*/
void rte_stats_bitrate_free(struct rte_stats_bitrates *bitrate_data);
+/**
+ * Allocate a bitrate statistics structure
+ *
+ * @return
+ * - Pointer to structure on success
+ * - NULL on error (zmalloc failure)
+ */
+struct rte_stats_bitrates *rte_stats_bitrate_create(void)
+ __rte_malloc __rte_dealloc(rte_stats_bitrate_free, 1);
+
/**
* Register bitrate statistics with the metric library.
*
--
2.45.2
More information about the dev
mailing list