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.
This commit is contained in:
1 parent
35d4e1bc53
commit
9b2fee66a2
2 files changed
+9
-3
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
Reference in new issue
Block a user