Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t] lib/igt_core: Free log_buffer entries on exit
@ 2024-11-07  7:02 Lucas De Marchi
  2024-11-07  8:05 ` ✓ Fi.CI.BAT: success for " Patchwork
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Lucas De Marchi @ 2024-11-07  7:02 UTC (permalink / raw)
  To: igt-dev; +Cc: Lucas De Marchi

Make sure the buffer entries are released, otherwise valgrind output
becomes each used entry as still reachable on exit (up to 256).

Test:
	# valgrind --leak-check=full  ./build/tests/xe_live_ktest  --r xe_mocs

Before:
	==16082== LEAK SUMMARY:
	==16082==    definitely lost: 0 bytes in 0 blocks
	==16082==    indirectly lost: 0 bytes in 0 blocks
	==16082==      possibly lost: 0 bytes in 0 blocks
	==16082==    still reachable: 33,473 bytes in 59 blocks

After:
	==15992== LEAK SUMMARY:
	==15992==    definitely lost: 0 bytes in 0 blocks
	==15992==    indirectly lost: 0 bytes in 0 blocks
	==15992==      possibly lost: 0 bytes in 0 blocks
	==15992==    still reachable: 31,083 bytes in 42 blocks

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
 lib/igt_core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 407f7b551..879d1ecd8 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -469,11 +469,21 @@ static void _igt_log_buffer_append(char *line)
 	pthread_mutex_unlock(&log_buffer_mutex);
 }
 
+static void _igt_log_buffer_reset_locked(void)
+{
+	for (; log_buffer.start != log_buffer.end; log_buffer.start++) {
+		free(log_buffer.entries[log_buffer.start]);
+		log_buffer.entries[log_buffer.start] = NULL;
+	}
+
+	log_buffer.start = log_buffer.end = 0;
+}
+
 static void _igt_log_buffer_reset(void)
 {
 	pthread_mutex_lock(&log_buffer_mutex);
 
-	log_buffer.start = log_buffer.end = 0;
+	_igt_log_buffer_reset_locked();
 
 	pthread_mutex_unlock(&log_buffer_mutex);
 }
@@ -624,8 +634,7 @@ static void _igt_log_buffer_dump(void)
 		i++;
 	} while (i != log_buffer.start && i != log_buffer.end);
 
-	/* reset the buffer */
-	log_buffer.start = log_buffer.end = 0;
+	_igt_log_buffer_reset_locked();
 
 	_log_line_fprintf(stderr, "****  END  ****\n");
 	pthread_mutex_unlock(&log_buffer_mutex);
-- 
2.47.0


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

end of thread, other threads:[~2024-11-18 15:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-07  7:02 [PATCH i-g-t] lib/igt_core: Free log_buffer entries on exit Lucas De Marchi
2024-11-07  8:05 ` ✓ Fi.CI.BAT: success for " Patchwork
2024-11-07  8:06 ` ✓ CI.xeBAT: " Patchwork
2024-11-07  9:28 ` ✗ Fi.CI.IGT: failure " Patchwork
2024-11-07 17:31 ` [PATCH i-g-t] " Kamil Konieczny
2024-11-07 18:36   ` Lucas De Marchi
2024-11-18 15:11     ` Vivekanandan, Balasubramani
2024-11-08 13:35 ` ✗ CI.xeFULL: failure for " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox