linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH libgpiod 0/3] dbus: client: fix memory leaks and errors
@ 2024-10-07 19:30 Bartosz Golaszewski
  2024-10-07 19:30 ` [PATCH libgpiod 1/3] dbus: client: notify: fix reference counting Bartosz Golaszewski
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-10-07 19:30 UTC (permalink / raw)
  To: Kent Gibson, Linus Walleij; +Cc: Bartosz Golaszewski, linux-gpio

The daemon gets good memory leak coverage just by running it through
valgrind and executing the gpiocli test-suite. The client is a bit
trickier to test so there sure will be more fixes coming.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
Bartosz Golaszewski (3):
      dbus: client: notify: fix reference counting
      dbus: client: notify: free chip and line lists at exit
      dbus: client: monitor: free the line list at exit

 dbus/client/monitor.c | 1 +
 dbus/client/notify.c  | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
---
base-commit: 0e4198b9eef1eeedf8cf12e970b36d4e50a1da48
change-id: 20241007-dbus-memory-fixes-3c9529124907

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH libgpiod 1/3] dbus: client: notify: fix reference counting
  2024-10-07 19:30 [PATCH libgpiod 0/3] dbus: client: fix memory leaks and errors Bartosz Golaszewski
@ 2024-10-07 19:30 ` Bartosz Golaszewski
  2024-10-07 19:30 ` [PATCH libgpiod 2/3] dbus: client: notify: free chip and line lists at exit Bartosz Golaszewski
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-10-07 19:30 UTC (permalink / raw)
  To: Kent Gibson, Linus Walleij; +Cc: Bartosz Golaszewski, linux-gpio

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

There's a reference overflow when adding chips to the global list and an
underflow when fetching existing chips from that list in connect_line().
Fix both issues.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 dbus/client/notify.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/dbus/client/notify.c b/dbus/client/notify.c
index 5c73343..6d51a6f 100644
--- a/dbus/client/notify.c
+++ b/dbus/client/notify.c
@@ -211,10 +211,10 @@ static void connect_line(gpointer elem, gpointer user_data)
 	if (data->scoped_chip) {
 		if (g_list_length(data->chips) == 0) {
 			chip = gpiodbus_object_get_chip(chip_obj);
-			data->chips = g_list_append(data->chips,
-						    g_object_ref(chip));
+			data->chips = g_list_append(data->chips, chip);
 		} else {
 			chip = g_list_first(data->chips)->data;
+			g_object_ref(chip);
 		}
 	} else {
 		chip = gpiodbus_object_get_chip(chip_obj);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH libgpiod 2/3] dbus: client: notify: free chip and line lists at exit
  2024-10-07 19:30 [PATCH libgpiod 0/3] dbus: client: fix memory leaks and errors Bartosz Golaszewski
  2024-10-07 19:30 ` [PATCH libgpiod 1/3] dbus: client: notify: fix reference counting Bartosz Golaszewski
@ 2024-10-07 19:30 ` Bartosz Golaszewski
  2024-10-07 19:30 ` [PATCH libgpiod 3/3] dbus: client: monitor: free the line list " Bartosz Golaszewski
  2024-10-09  7:33 ` [PATCH libgpiod 0/3] dbus: client: fix memory leaks and errors Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-10-07 19:30 UTC (permalink / raw)
  To: Kent Gibson, Linus Walleij; +Cc: Bartosz Golaszewski, linux-gpio

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

We don't free the lists storing line and chip objects for the duration
of the program when exiting. Fix it.

Note: these objects need to be kept alive for D-Bus events to work.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 dbus/client/notify.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/dbus/client/notify.c b/dbus/client/notify.c
index 6d51a6f..800dd24 100644
--- a/dbus/client/notify.c
+++ b/dbus/client/notify.c
@@ -289,6 +289,8 @@ int gpiocli_notify_main(int argc, char **argv)
 
 	g_main_loop_run(loop);
 
+	g_list_free_full(data.lines, g_object_unref);
+	g_list_free_full(data.chips, g_object_unref);
 	g_bus_unwatch_name(watch_id);
 
 	return EXIT_SUCCESS;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH libgpiod 3/3] dbus: client: monitor: free the line list at exit
  2024-10-07 19:30 [PATCH libgpiod 0/3] dbus: client: fix memory leaks and errors Bartosz Golaszewski
  2024-10-07 19:30 ` [PATCH libgpiod 1/3] dbus: client: notify: fix reference counting Bartosz Golaszewski
  2024-10-07 19:30 ` [PATCH libgpiod 2/3] dbus: client: notify: free chip and line lists at exit Bartosz Golaszewski
@ 2024-10-07 19:30 ` Bartosz Golaszewski
  2024-10-09  7:33 ` [PATCH libgpiod 0/3] dbus: client: fix memory leaks and errors Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-10-07 19:30 UTC (permalink / raw)
  To: Kent Gibson, Linus Walleij; +Cc: Bartosz Golaszewski, linux-gpio

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Free the list of line proxies stored for the duration of the program at
exit to fix a memory leak.

Note: these objects need to be kept alive for D-Bus events to work.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 dbus/client/monitor.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/dbus/client/monitor.c b/dbus/client/monitor.c
index 3bd25b8..df7eb51 100644
--- a/dbus/client/monitor.c
+++ b/dbus/client/monitor.c
@@ -185,6 +185,7 @@ int gpiocli_monitor_main(int argc, char **argv)
 
 	g_main_loop_run(loop);
 
+	g_list_free_full(data.lines, g_object_unref);
 	g_bus_unwatch_name(watch_id);
 
 	return EXIT_SUCCESS;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH libgpiod 0/3] dbus: client: fix memory leaks and errors
  2024-10-07 19:30 [PATCH libgpiod 0/3] dbus: client: fix memory leaks and errors Bartosz Golaszewski
                   ` (2 preceding siblings ...)
  2024-10-07 19:30 ` [PATCH libgpiod 3/3] dbus: client: monitor: free the line list " Bartosz Golaszewski
@ 2024-10-09  7:33 ` Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-10-09  7:33 UTC (permalink / raw)
  To: Kent Gibson, Linus Walleij, Bartosz Golaszewski
  Cc: Bartosz Golaszewski, linux-gpio

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Mon, 07 Oct 2024 21:30:21 +0200, Bartosz Golaszewski wrote:
> The daemon gets good memory leak coverage just by running it through
> valgrind and executing the gpiocli test-suite. The client is a bit
> trickier to test so there sure will be more fixes coming.
> 
> 

Applied, thanks!

[1/3] dbus: client: notify: fix reference counting
      commit: c87847b23b398d0b62185cd8191aaa09113debdb
[2/3] dbus: client: notify: free chip and line lists at exit
      commit: 85471d394bab3c95e7b968c8a3df9a7ff894fce4
[3/3] dbus: client: monitor: free the line list at exit
      commit: 392cae9e4233040e1d1a171552490fa9be7fd6dd

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-09  7:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-07 19:30 [PATCH libgpiod 0/3] dbus: client: fix memory leaks and errors Bartosz Golaszewski
2024-10-07 19:30 ` [PATCH libgpiod 1/3] dbus: client: notify: fix reference counting Bartosz Golaszewski
2024-10-07 19:30 ` [PATCH libgpiod 2/3] dbus: client: notify: free chip and line lists at exit Bartosz Golaszewski
2024-10-07 19:30 ` [PATCH libgpiod 3/3] dbus: client: monitor: free the line list " Bartosz Golaszewski
2024-10-09  7:33 ` [PATCH libgpiod 0/3] dbus: client: fix memory leaks and errors Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).