Skip to content

Commit

Permalink
telnet_server: fix valgrind error
Browse files Browse the repository at this point in the history
Error: Uninitialised value was created by a heap allocation
at telnet_new_connection (telnet_server.c:227)

Signed-off-by: Erhan Kurubas <[email protected]>
Change-Id: I698a3648be698c93a2395a718ee1ade028226995
Reviewed-on: https://review.openocd.org/c/openocd/+/7006
Tested-by: jenkins
Reviewed-by: Tomas Vanek <[email protected]>
  • Loading branch information
erhankur authored and tom-van committed Jun 8, 2022
1 parent 4f42600 commit 822097a
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/server/telnet_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ static int telnet_new_connection(struct connection *connection)
{
struct telnet_connection *telnet_connection;
struct telnet_service *telnet_service = connection->service->priv;
int i;

telnet_connection = malloc(sizeof(struct telnet_connection));
telnet_connection = calloc(1, sizeof(struct telnet_connection));

if (!telnet_connection) {
LOG_ERROR("Failed to allocate telnet connection.");
Expand All @@ -234,9 +233,6 @@ static int telnet_new_connection(struct connection *connection)
connection->priv = telnet_connection;

/* initialize telnet connection information */
telnet_connection->closed = false;
telnet_connection->line_size = 0;
telnet_connection->line_cursor = 0;
telnet_connection->prompt = strdup("> ");
telnet_connection->prompt_visible = true;
telnet_connection->state = TELNET_STATE_DATA;
Expand All @@ -257,11 +253,6 @@ static int telnet_new_connection(struct connection *connection)
telnet_write(connection, "\r", 1);
telnet_prompt(connection);

/* initialize history */
for (i = 0; i < TELNET_LINE_HISTORY_SIZE; i++)
telnet_connection->history[i] = NULL;
telnet_connection->next_history = 0;
telnet_connection->current_history = 0;
telnet_load_history(telnet_connection);

log_add_callback(telnet_log_callback, connection);
Expand Down

0 comments on commit 822097a

Please sign in to comment.