From da105ca2b3c394c49c32caaddaa7a7f90dc1d5b8 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Sat, 11 Apr 2026 13:33:49 +0000 Subject: [PATCH] fix(test/tap): NULL-init + remove dead cleanup labels reg_test_mariadb_metadata_check-t.cpp: - Remove the dead 'cleanup:' label in main(). The label was empty (no cleanup body, just fell through to return exit_status()), so deleting it is purely warning cleanup; no behavior change. test_rw_binary_data-t.cpp: - Fix NULL-deref UB and cross-leak: proxy and admin were each mysql_ init()'d without a NULL check, then immediately passed to mysql_ real_connect. On either side failing, the other side's already- initialized handle was leaked because every error path did a bare 'return EXIT_FAILURE'. - Remove the unused 'cleanup:' label at the end of main(). The label was fall-through-only (nothing ever jumped to it) which is why -Wunused-label fired; behavior is unchanged because the happy path still runs mysql_close on both handles. - Added a TODO comment noting that many MYSQL_QUERY calls in the test body still leak proxy/admin on query failure; restructuring the whole main() is out of scope for this batch. --- .../reg_test_mariadb_metadata_check-t.cpp | 2 -- test/tap/tests/test_rw_binary_data-t.cpp | 22 +++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/test/tap/tests/reg_test_mariadb_metadata_check-t.cpp b/test/tap/tests/reg_test_mariadb_metadata_check-t.cpp index d6c940f0f..531e151ba 100644 --- a/test/tap/tests/reg_test_mariadb_metadata_check-t.cpp +++ b/test/tap/tests/reg_test_mariadb_metadata_check-t.cpp @@ -366,7 +366,5 @@ int main(int argc, char** argv) { test_malformed_packet(); test_integrity_check(cl); -cleanup: - return exit_status(); } diff --git a/test/tap/tests/test_rw_binary_data-t.cpp b/test/tap/tests/test_rw_binary_data-t.cpp index 748d62aed..8713d4182 100644 --- a/test/tap/tests/test_rw_binary_data-t.cpp +++ b/test/tap/tests/test_rw_binary_data-t.cpp @@ -394,14 +394,30 @@ int main(int argc, char** argv) { MYSQL* proxy = mysql_init(NULL); MYSQL* admin = mysql_init(NULL); + if (!proxy) { + fprintf(stderr, "File %s, line %d, Error: mysql_init failed for 'proxy'\n", + __FILE__, __LINE__); + if (admin) { mysql_close(admin); } + return EXIT_FAILURE; + } + if (!admin) { + fprintf(stderr, "File %s, line %d, Error: mysql_init failed for 'admin'\n", + __FILE__, __LINE__); + mysql_close(proxy); + return EXIT_FAILURE; + } if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); + mysql_close(proxy); + mysql_close(admin); return EXIT_FAILURE; } if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { // if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, 13306, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); + mysql_close(proxy); + mysql_close(admin); return EXIT_FAILURE; } @@ -504,8 +520,10 @@ int main(int argc, char** argv) { ok(count_star == NUM_TESTS * 3, "Digest matches expected 'count_star' number"); } -cleanup: - + // Happy-path cleanup. Note: many MYSQL_QUERY calls above do an early + // 'return EXIT_FAILURE' on query failure, so they leak proxy/admin. + // Fixing that would require restructuring the whole main(), left for + // a follow-up. mysql_close(proxy); mysql_close(admin);