[PATCH 3/4] bobject: free object name in bobject_del()
Sascha Hauer
s.hauer at pengutronix.de
Fri Nov 7 04:00:53 PST 2025
We have bobject_free() which removes all parameters and frees the
bobject. This works for bobjects which have been allocated with
bobject_alloc(). struct device has a bobject embedded and is freed
along with the device, so bobject_free() is inappropriate and
bobject_del() is called instead. This however doesn't free the bobjects
name which then leaks when the device is freed.
To fix this move the freeing of the bobject name to bobject_del(). To
make this work with CONFIG_PARAMETER disabled drop the static inline
wrapper.
While at it fix the function name in the bobject_del() function
description.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
include/bobject.h | 4 ----
lib/bobject.c | 7 +++----
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/include/bobject.h b/include/bobject.h
index 34cf9d62bc6e3373b7b6b6073640aeceadda7c8f..76c9158b71a6a68994ee3491c781a6d7d7f2f9ac 100644
--- a/include/bobject.h
+++ b/include/bobject.h
@@ -39,10 +39,6 @@ static inline void bobject_init(struct bobject *bobj)
struct bobject *bobject_alloc(const char *name);
void bobject_free(struct bobject *bobj);
-#ifdef CONFIG_PARAMETER
void bobject_del(struct bobject *bobj);
-#else
-static inline void bobject_del(struct bobject *bobj) { }
-#endif
#endif
diff --git a/lib/bobject.c b/lib/bobject.c
index eb140b90a2d58db2497ba4b95e1995f4965a1d34..373575eade0c1ceb4c2198cfab1005a8e5230caa 100644
--- a/lib/bobject.c
+++ b/lib/bobject.c
@@ -51,15 +51,13 @@ void bobject_free(struct bobject *bobj)
if (!bobj)
return;
- free(bobj->name);
bobject_del(bobj);
free(bobj);
}
EXPORT_SYMBOL_GPL(bobject_free);
-#ifdef CONFIG_PARAMETER
/**
- * bobject_remove_parameters - remove all parameters from a bobject and free their
+ * bobject_del - remove all parameters from a bobject and free their
* memory
* @param bobject The barebox object
*/
@@ -69,6 +67,7 @@ void bobject_del(struct bobject *bobj)
list_for_each_entry_safe(p, n, &bobj->parameters, list)
param_remove(p);
+
+ free(bobj->name);
}
EXPORT_SYMBOL(bobject_del);
-#endif
--
2.47.3
More information about the barebox
mailing list