From 9b2fee66a26a47c55b3481c90cd8c1313307f5f2 Mon Sep 17 00:00:00 2001 From: lotherk Date: Mon, 23 Nov 2026 13:21:50 +0000 Subject: [PATCH] tests: valgrind-clean -- free the registry, NUL where the read stopped Valgrind over the test binaries found two test-side defects, no production path: - test_skills never called sp_registry_free(), so the 448 bytes sp_registry_add() copied for the three skill tools were reported as "definitely lost" on every run. Freed now. - test_providers read the /connect drop-in into a 1024-byte stack buffer and NUL-ed only the first and last byte, so strstr() walked through uninitialised bytes between them ("Conditional jump or move depends on uninitialised value"). Terminated at the read length instead. Both runs are clean: valgrind tests/test_skills -> 0 errors, exit 0; valgrind tests/test_providers -> 0 errors, exit 0. make check: all tests passed. tests/check_asan.sh: all 46 test binaries clean. --- tests/test_providers.c | 9 ++++++--- tests/test_skills.c | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_providers.c b/tests/test_providers.c index 5df66cf..586c8db 100644 --- a/tests/test_providers.c +++ b/tests/test_providers.c @@ -197,9 +197,12 @@ main(void) mf = fopen(mpath, "r"); CHECK(mf != NULL); if (mf != NULL) { - mbuf[0] = '\0'; - (void)fread(mbuf, 1, sizeof(mbuf) - 1, mf); - mbuf[sizeof(mbuf) - 1] = '\0'; + size_t got; + + /* terminate where the read stopped: the rest of the + * buffer is not text, and strstr() would walk into it */ + got = fread(mbuf, 1, sizeof(mbuf) - 1, mf); + mbuf[got] = '\0'; fclose(mf); /* the choice is a default; the provider carries the rest */ CHECK(strstr(mbuf, "default = ocgo/other-model") != NULL); diff --git a/tests/test_skills.c b/tests/test_skills.c index abc4d96..63ca5c7 100644 --- a/tests/test_skills.c +++ b/tests/test_skills.c @@ -98,6 +98,9 @@ main(void) CHECK(strstr(out.p, "no skill 'nope'") != NULL); sp_buf_free(&out); + /* the registry owns what sp_registry_add copied: free it, or the + * test leaks what production never does */ + sp_registry_free(&r); { char cmd[700];