mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 3/4] bobject: free object name in bobject_del()
Date: Fri, 07 Nov 2025 13:00:53 +0100	[thread overview]
Message-ID: <20251107-memleaks-v1-3-c7b74a2ae9db@pengutronix.de> (raw)
In-Reply-To: <20251107-memleaks-v1-0-c7b74a2ae9db@pengutronix.de>

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@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




  parent reply	other threads:[~2025-11-07 12:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-07 12:00 [PATCH 0/4] fix some memory leaks Sascha Hauer
2025-11-07 12:00 ` [PATCH 1/4] tlv: fix memory leak Sascha Hauer
2025-11-07 12:00 ` [PATCH 2/4] of: free of_fixup in of_unregister_fixup() Sascha Hauer
2025-11-07 12:00 ` Sascha Hauer [this message]
2025-11-10 13:48   ` [PATCH 3/4] bobject: free object name in bobject_del() Sascha Hauer
2025-11-07 12:00 ` [PATCH 4/4] bfetch: fix memory leak Sascha Hauer
2025-11-10 13:46 ` [PATCH 0/4] fix some memory leaks Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251107-memleaks-v1-3-c7b74a2ae9db@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox