diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-05-13 10:58:41 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-05-13 11:37:46 +0200 |
commit | cd917f48454875ad6b7fc69455281d72760c44ee (patch) | |
tree | 70a7a43fe43b7f893468f9120def5513774a242c /src/server.c | |
parent | add command module to handle request-response communications (diff) | |
download | cimple-cd917f48454875ad6b7fc69455281d72760c44ee.tar.gz cimple-cd917f48454875ad6b7fc69455281d72760c44ee.zip |
best practices & coding style fixes
* I don't really need to declare all variables at the top of the
function anymore.
* Default-initialize variables more.
* Don't set the output parameter until the object is completely
constructed.
Diffstat (limited to 'src/server.c')
-rw-r--r-- | src/server.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/server.c b/src/server.c index 806da11..1efbbb5 100644 --- a/src/server.c +++ b/src/server.c @@ -35,16 +35,14 @@ struct server { int server_create(struct server **_server, const struct settings *settings) { - struct server *server; struct storage_settings storage_settings; int ret = 0; - *_server = malloc(sizeof(struct server)); - if (!*_server) { + struct server *server = malloc(sizeof(struct server)); + if (!server) { log_errno("malloc"); return -1; } - server = *_server; ret = pthread_mutex_init(&server->server_mtx, NULL); if (ret) { @@ -75,6 +73,7 @@ int server_create(struct server **_server, const struct settings *settings) ci_queue_create(&server->ci_queue); + *_server = server; return ret; destroy_storage: @@ -111,7 +110,7 @@ static int server_has_runs(const struct server *server) static int worker_ci_run(int fd, const struct ci_queue_entry *ci_run) { - struct msg *request, *response; + struct msg *request = NULL, *response = NULL; int ret = 0; const char *argv[] = {CMD_CI_RUN, ci_queue_entry_get_url(ci_run), @@ -242,7 +241,7 @@ static int msg_new_worker_handler(int client_fd, UNUSED const struct msg *reques static int msg_ci_run_queue(struct server *server, const char *url, const char *rev) { - struct ci_queue_entry *entry; + struct ci_queue_entry *entry = NULL; int ret = 0; ret = pthread_mutex_lock(&server->server_mtx); |