WIP:Fix memory management for #22103 tests
Code movement in the commit introducings tests for #22103 uncovered a latent memory management bug.
Refactor the log message checking from test_options_checkmsgs() into a helper test_options_checklog(). This avoids a memory leak (and possible double-free) in a test failure condition.
Don't reuse variables (especially pointers to allocated memory!) for multiple unrelated purposes.
Fixes CID 1405778.