server: free strduped port numbers

Although the leak is negligible, the clean heap on exit will ease
valgrind testing.

Change-Id: I3a7a9c8e8dc7557aa51d0b9caa244537e5e7007d
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4410
Tested-by: jenkins
riscv-compliance-dev
Tomas Vanek 2018-02-15 00:22:42 +01:00
parent ae5b30ae96
commit 33a3355304
11 changed files with 35 additions and 0 deletions

View File

@ -345,6 +345,9 @@ int openocd_main(int argc, char *argv[])
/* Start the executable meat that can evolve into thread in future. */
ret = openocd_thread(argc, argv, cmd_ctx);
gdb_service_free();
server_free();
unregister_all_commands(cmd_ctx, NULL);
/* Shutdown commandline interface */

View File

@ -3572,3 +3572,9 @@ int gdb_register_commands(struct command_context *cmd_ctx)
gdb_port_next = strdup("3333");
return register_commands(cmd_ctx, NULL, gdb_command_handlers);
}
void gdb_service_free(void)
{
free(gdb_port);
free(gdb_port_next);
}

View File

@ -36,6 +36,7 @@ struct reg;
int gdb_target_add_all(struct target *target);
int gdb_register_commands(struct command_context *command_context);
void gdb_service_free(void);
int gdb_put_packet(struct connection *connection, char *buffer, int len);

View File

@ -641,6 +641,13 @@ int server_quit(void)
return last_signal;
}
void server_free(void)
{
tcl_service_free();
telnet_service_free();
jsp_service_free();
}
void exit_on_signal(int sig)
{
#ifndef _WIN32

View File

@ -82,6 +82,7 @@ int add_service(char *name, const char *port,
int server_preinit(void);
int server_init(struct command_context *cmd_ctx);
int server_quit(void);
void server_free(void);
void exit_on_signal(int);
int server_loop(struct command_context *command_context);

View File

@ -359,3 +359,8 @@ int tcl_register_commands(struct command_context *cmd_ctx)
tcl_port = strdup("6666");
return register_commands(cmd_ctx, NULL, tcl_command_handlers);
}
void tcl_service_free(void)
{
free(tcl_port);
}

View File

@ -22,5 +22,6 @@
int tcl_init(void);
int tcl_register_commands(struct command_context *cmd_ctx);
void tcl_service_free(void);
#endif /* OPENOCD_SERVER_TCL_SERVER_H */

View File

@ -719,3 +719,8 @@ int telnet_register_commands(struct command_context *cmd_ctx)
telnet_port = strdup("4444");
return register_commands(cmd_ctx, NULL, telnet_command_handlers);
}
void telnet_service_free(void)
{
free(telnet_port);
}

View File

@ -64,5 +64,6 @@ struct telnet_service {
int telnet_init(char *banner);
int telnet_register_commands(struct command_context *command_context);
void telnet_service_free(void);
#endif /* OPENOCD_SERVER_TELNET_SERVER_H */

View File

@ -242,3 +242,7 @@ int jsp_register_commands(struct command_context *cmd_ctx)
return register_commands(cmd_ctx, NULL, jsp_command_handlers);
}
void jsp_service_free(void)
{
free(jsp_port);
}

View File

@ -13,5 +13,6 @@ struct jsp_service {
int jsp_init(struct or1k_jtag *jtag_info, char *banner);
int jsp_register_commands(struct command_context *cmd_ctx);
void jsp_service_free(void);
#endif /* OPENOCD_TARGET_OPENRISC_JSP_SERVER_H */