Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [PATCH i-g-t] lib/igt_core: Free log_buffer entries on exit
Date: Wed,  6 Nov 2024 23:02:08 -0800	[thread overview]
Message-ID: <20241107070208.3143050-1-lucas.demarchi@intel.com> (raw)

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


             reply	other threads:[~2024-11-07  7:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07  7:02 Lucas De Marchi [this message]
2024-11-07  8:05 ` ✓ Fi.CI.BAT: success for lib/igt_core: Free log_buffer entries on exit 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

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=20241107070208.3143050-1-lucas.demarchi@intel.com \
    --to=lucas.demarchi@intel.com \
    --cc=igt-dev@lists.freedesktop.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