1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-31 00:03:07 +03:00

test_server: Use dynamically allocated state

The "dynamically" loaded server is using allocated state and using something
else complicates proper cleanup.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Norbert Pocs <npocs@redhat.com>
This commit is contained in:
Jakub Jelen
2023-04-28 18:09:19 +02:00
parent e4bf3b97b4
commit ce7cc49465

View File

@ -596,9 +596,12 @@ int main(UNUSED_PARAM(int argc), UNUSED_PARAM(char **argv))
.address = NULL, .address = NULL,
.with_global_config = true, .with_global_config = true,
}; };
struct server_state_st state = { struct server_state_st *state = calloc(1, sizeof(struct server_state_st));
.address = NULL,
}; if (state == NULL) {
printf("Failed to allocate memory\n");
return -1;
}
#ifdef HAVE_ARGP_H #ifdef HAVE_ARGP_H
argp_parse (&argp, argc, argv, 0, 0, &arguments); argp_parse (&argp, argc, argv, 0, 0, &arguments);
@ -608,6 +611,8 @@ int main(UNUSED_PARAM(int argc), UNUSED_PARAM(char **argv))
pid_file = fopen(arguments.pid_file, "w"); pid_file = fopen(arguments.pid_file, "w");
if (pid_file == NULL) { if (pid_file == NULL) {
rc = -1; rc = -1;
free_server_state(state);
SAFE_FREE(state);
goto free_arguments; goto free_arguments;
} }
pid = getpid(); pid = getpid();
@ -616,22 +621,19 @@ int main(UNUSED_PARAM(int argc), UNUSED_PARAM(char **argv))
} }
/* Initialize the state using default or given parameters */ /* Initialize the state using default or given parameters */
rc = init_server_state(&state, &arguments); rc = init_server_state(state, &arguments);
if (rc != 0) { if (rc != 0) {
free_server_state(state);
SAFE_FREE(state);
goto free_arguments; goto free_arguments;
} }
/* Free the arguments used to initialize the state before fork */ /* Free the arguments used to initialize the state before fork */
free_arguments(&arguments); free_arguments(&arguments);
/* Run the server */ /* Run the server: Frees the state in all processes */
rc = run_server(&state); rc = run_server(state);
if (rc != 0) {
goto free_state;
}
free_state:
free_server_state(&state);
free_arguments: free_arguments:
free_arguments(&arguments); free_arguments(&arguments);
return rc; return rc;