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.
lint-tap-tests-static-analysis
Rene Cannao 1 month ago
parent fcfeec42a9
commit da105ca2b3

@ -366,7 +366,5 @@ int main(int argc, char** argv) {
test_malformed_packet();
test_integrity_check(cl);
cleanup:
return exit_status();
}

@ -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);

Loading…
Cancel
Save