diff --git a/server/core/server.cc b/server/core/server.cc index 72fbabe1f..786ccc75b 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -191,6 +191,7 @@ server_free(SERVER *tofreeserver) /* Clean up session and free the memory */ MXS_FREE(tofreeserver->protocol); MXS_FREE(tofreeserver->name); + MXS_FREE(tofreeserver->authenticator); server_parameter_free(tofreeserver->parameters); if (tofreeserver->persistent) @@ -201,6 +202,7 @@ server_free(SERVER *tofreeserver) { dcb_persistent_clean_count(tofreeserver->persistent[i], i, true); } + MXS_FREE(tofreeserver->persistent); } delete tofreeserver->disk_space_threshold; MXS_FREE(tofreeserver); diff --git a/server/core/test/test_server.cc b/server/core/test/test_server.cc index e9f299f6b..992bf34d9 100644 --- a/server/core/test/test_server.cc +++ b/server/core/test/test_server.cc @@ -131,6 +131,8 @@ bool test_load_config(const char *input, SERVER *server) "Server authenticators differ"); TEST(server->port == atoi(config_get_param(param, "port")->value), "Server ports differ"); TEST(create_new_server(obj) == 0, "Failed to create server from loaded config"); + duplicate_context_finish(&dcontext); + config_context_free(obj); } } diff --git a/server/modules/filter/cache/test/testkeygeneration.cc b/server/modules/filter/cache/test/testkeygeneration.cc index 5a5a2d0f6..d6b470ca9 100644 --- a/server/modules/filter/cache/test/testkeygeneration.cc +++ b/server/modules/filter/cache/test/testkeygeneration.cc @@ -125,7 +125,7 @@ int test(StorageFactory& factory, istream& in) int main(int argc, char* argv[]) { int rv = EXIT_FAILURE; - + StorageFactory* pFactory; if ((argc == 2) || (argc == 3)) { char* libdir = MXS_STRDUP("../../../../../query_classifier/qc_sqlite/"); @@ -139,7 +139,7 @@ int main(int argc, char* argv[]) libdir = MXS_STRDUP("../storage/storage_inmemory/"); set_libdir(libdir); - StorageFactory* pFactory = StorageFactory::Open(zModule); + pFactory = StorageFactory::Open(zModule); if (pFactory) { @@ -182,6 +182,7 @@ int main(int argc, char* argv[]) // TODO: Remove this once globally allocated memory is freed MXS_FREE(libdir); + delete pFactory; } else { diff --git a/server/modules/routing/binlogrouter/test/testbinlog.cc b/server/modules/routing/binlogrouter/test/testbinlog.cc index 1869e148f..994c46e76 100644 --- a/server/modules/routing/binlogrouter/test/testbinlog.cc +++ b/server/modules/routing/binlogrouter/test/testbinlog.cc @@ -54,6 +54,7 @@ static void printVersion(const char *progname); static void printUsage(const char *progname); +static void master_free_parsed_options(CHANGE_MASTER_OPTIONS *options); extern int blr_test_parse_change_master_command(char *input, char *error_string, CHANGE_MASTER_OPTIONS *config); extern char *blr_test_set_master_logfile(ROUTER_INSTANCE *router, char *filename, char *error); @@ -76,6 +77,12 @@ int main(int argc, char **argv) int rc; char error_string[BINLOG_ERROR_MSG_LEN + 1] = ""; CHANGE_MASTER_OPTIONS change_master; + change_master.host = NULL; + change_master.port = NULL; + change_master.user = NULL; + change_master.password = NULL; + change_master.binlog_file = NULL; + change_master.binlog_pos = NULL; char query[512 + 1] = ""; char saved_query[512 + 1] = ""; int command_offset = strlen("CHANGE MASTER TO"); @@ -330,7 +337,7 @@ int main(int argc, char **argv) } tests++; - + master_free_parsed_options(&change_master); /** * Test 9: 1 valid option with value * @@ -349,7 +356,7 @@ int main(int argc, char **argv) { printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); } - + master_free_parsed_options(&change_master); tests++; /** @@ -370,7 +377,7 @@ int main(int argc, char **argv) { printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); } - + master_free_parsed_options(&change_master); tests++; /** @@ -391,7 +398,7 @@ int main(int argc, char **argv) { printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); } - + master_free_parsed_options(&change_master); tests++; /** @@ -412,7 +419,7 @@ int main(int argc, char **argv) { printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); } - + master_free_parsed_options(&change_master); tests++; /** @@ -434,7 +441,7 @@ int main(int argc, char **argv) { printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); } - + master_free_parsed_options(&change_master); tests++; /** @@ -456,7 +463,7 @@ int main(int argc, char **argv) { printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); } - + master_free_parsed_options(&change_master); tests++; /** @@ -479,7 +486,7 @@ int main(int argc, char **argv) { printf("Test %d PASSED, valid / not valid options for [%s]\n", tests, saved_query); } - + master_free_parsed_options(&change_master); tests++; /** @@ -503,6 +510,16 @@ int main(int argc, char **argv) { printf("Test %d PASSED, valid options for [%s]\n", tests, saved_query); } + MXS_FREE(change_master.host); + change_master.host = NULL; + MXS_FREE(change_master.port); + change_master.port = NULL; + MXS_FREE(change_master.user); + change_master.user = NULL; + MXS_FREE(change_master.password); + change_master.password = NULL; + MXS_FREE(change_master.binlog_pos); + change_master.binlog_pos = NULL; tests++; @@ -510,7 +527,7 @@ int main(int argc, char **argv) /** * Test 17: use current binlog filename in master_state != BLRM_UNCONFIGURED - * and try to set a new filename with wront format from previous test + * and try to set a new filename with wrong format from previous test * * Expected master_log_file is NULL and error_string is not empty */ @@ -540,7 +557,8 @@ int main(int argc, char **argv) } tests++; - + MXS_FREE(change_master.binlog_file); + change_master.binlog_file = NULL; printf("--- MASTER_LOG_POS and MASTER_LOG_FILE rule/constraints checks ---\n"); /******************************************** @@ -846,8 +864,48 @@ int main(int argc, char **argv) mxs_log_flush_sync(); mxs_log_finish(); - + MXS_FREE(inst->user); + MXS_FREE(inst->password); + MXS_FREE(inst->fileroot); MXS_FREE(inst); MXS_FREE(roptions); return 0; } + +static void +master_free_parsed_options(CHANGE_MASTER_OPTIONS *options) +{ + if (options->host) + { + MXS_FREE(options->host); + options->host = NULL; + } + if (options->port) + { + MXS_FREE(options->port); + options->port = NULL; + } + if (options->user) + { + MXS_FREE(options->user); + options->user = NULL; + } + + if (options->password) + { + MXS_FREE(options->password); + options->password = NULL; + } + + if (options->binlog_file) + { + MXS_FREE(options->binlog_file); + options->binlog_file = NULL; + } + + if (options->binlog_pos) + { + MXS_FREE(options->binlog_pos); + options->binlog_pos = NULL; + } +}