Skip to content

Commit

Permalink
cleanup: clean up use of *free functions with return type void (netse…
Browse files Browse the repository at this point in the history
…c-ethz#38)

(Also fix one occurence of `(void)synchronize_worker`.)
  • Loading branch information
marcfrei authored Jan 8, 2024
1 parent 30c06ef commit 7cd734d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
18 changes: 9 additions & 9 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ lf_config_new_from_file(const char *filename)
if (fread(file_content, file_size, 1, file) != 1) {
LF_LOG(ERR, "Unable to read content of %s\n", filename);
(void)fclose(file);
(void)free(file_content);
free(file_content);
return NULL;
}

Expand All @@ -825,29 +825,29 @@ lf_config_new_from_file(const char *filename)
/* Initialize config struct. Set all to 0. */
config = lf_config_new();
if (config == NULL) {
(void)free(file_content);
free(file_content);
return NULL;
}

json_val = json_parse(file_content, file_size);
if (json_val == NULL) {
LF_LOG(ERR, "Unable to parse json.\n");
(void)free(file_content);
(void)free(config);
free(file_content);
free(config);
return NULL;
}

res = parse_config(json_val, config);
if (res != 0) {
LF_LOG(ERR, "Unable to parse config.\n");
(void)free(file_content);
(void)free(config);
(void)json_value_free(json_val);
free(file_content);
free(config);
json_value_free(json_val);
return NULL;
}

(void)free(file_content);
(void)json_value_free(json_val);
free(file_content);
json_value_free(json_val);

return config;
}
Expand Down
20 changes: 10 additions & 10 deletions src/keymanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ lf_keymanager_service_update(struct lf_keymanager *km)
ns_now + LF_DRKEY_PREFETCHING_PERIOD,
&new_data->inbound_key);
if (key_id < 0) {
(void)rte_free(new_data);
rte_free(new_data);
err = -1;
goto exit;
}
Expand Down Expand Up @@ -232,7 +232,7 @@ lf_keymanager_service_update(struct lf_keymanager *km)
ns_now + LF_DRKEY_PREFETCHING_PERIOD,
&new_data->outbound_key);
if (key_id < 0) {
(void)rte_free(new_data);
rte_free(new_data);
err = -1;
goto exit;
}
Expand All @@ -259,8 +259,8 @@ lf_keymanager_service_update(struct lf_keymanager *km)
exit:
if (free_list != NULL) {
/* free old data after no worker accesses it anymore */
(void)synchronize_worker(km);
(void)linked_list_free(free_list);
synchronize_worker(km);
linked_list_free(free_list);
}
if (err != 0) {
LF_KEYMANAGER_LOG(ERR, "Error occurred during update (err = %d)\n",
Expand Down Expand Up @@ -340,7 +340,7 @@ key_dictionary_init(uint32_t size)

if (dic == NULL) {
LF_KEYMANAGER_LOG(ERR, "Hash creation failed with: %d\n", errno);
(void)rte_hash_free(dic);
rte_hash_free(dic);
return NULL;
}

Expand All @@ -361,9 +361,9 @@ key_dictionary_free(struct rte_hash *dict)

for (iterator = 0; rte_hash_iterate(dict, (void *)&key_ptr, (void **)&data,
&iterator) >= 0;) {
(void)rte_free(data);
rte_free(data);
}
(void)rte_hash_free(dict);
rte_hash_free(dict);
}

int
Expand Down Expand Up @@ -475,7 +475,7 @@ lf_keymanager_apply_config(struct lf_keymanager *km,
res = rte_hash_add_key_data(km->dict, &key, (void *)dictionary_data);
if (res != 0) {
LF_KEYMANAGER_LOG(ERR, "Add key failed with %d!\n", key_id);
(void)rte_free(dictionary_data);
rte_free(dictionary_data);
err = 1;
break;
}
Expand All @@ -488,8 +488,8 @@ lf_keymanager_apply_config(struct lf_keymanager *km,
exit_unlock:
if (free_list != NULL) {
/* free old data after no worker accesses it anymore */
(void)synchronize_worker(km);
(void)linked_list_free(free_list);
synchronize_worker(km);
linked_list_free(free_list);
}

(void)rte_spinlock_unlock(&km->management_lock);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/table/asdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ lf_asdict_new_with_data(int initial_size, int data_size)
void
lf_asdict_free(struct lf_asdict *dic)
{
(void)rte_free(dic->data_array);
rte_free(dic->data_array);
rte_hash_free(dic->hash_table);
(void)rte_free(dic);
rte_free(dic);
}

int
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ init_rcu_qs(uint16_t nb_qs_vars, struct rte_rcu_qsbr **qsv)
/* initialize QS variable for all workers */
if (rte_rcu_qsbr_init(*qsv, nb_qs_vars) != 0) {
LF_LOG(ERR, "RCU QSBR init failed\n");
(void)rte_free(*qsv);
rte_free(*qsv);
return -1;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/ratelimiter.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ dictionary_set(struct rte_hash *dict,
(void *)dictionary_data);
if (res != 0) {
LF_RATELIMITER_LOG(ERR, "Fail to add dictionary entry.\n");
(void)rte_free(dictionary_data);
rte_free(dictionary_data);
return res;
}
key_id = rte_hash_lookup(dict, dictionary_key);
Expand Down
4 changes: 2 additions & 2 deletions src/test/keymanager_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ new_rcu_qs(uint16_t nb_workers)
/* initialize QS variable for all workers */
if (rte_rcu_qsbr_init(qsv, nb_workers) != 0) {
LF_LOG(ERR, "RCU QSBR init failed\n");
(void)rte_free(qsv);
rte_free(qsv);
return NULL;
}
return qsv;
Expand All @@ -56,7 +56,7 @@ new_rcu_qs(uint16_t nb_workers)
void
free_rcu_qs(struct rte_rcu_qsbr *qsv)
{
(void)rte_free(qsv);
rte_free(qsv);
}

void
Expand Down
4 changes: 2 additions & 2 deletions src/test/ratelimiter_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ new_rcu_qs(uint16_t nb_workers)
/* initialize QS variable for all workers */
if (rte_rcu_qsbr_init(qsv, nb_workers) != 0) {
LF_LOG(ERR, "RCU QSBR init failed\n");
(void)rte_free(qsv);
rte_free(qsv);
return NULL;
}
return qsv;
Expand All @@ -56,7 +56,7 @@ new_rcu_qs(uint16_t nb_workers)
void
free_rcu_qs(struct rte_rcu_qsbr *qsv)
{
(void)rte_free(qsv);
rte_free(qsv);
}

struct lf_ratelimiter *
Expand Down
2 changes: 1 addition & 1 deletion src/test/rcu_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ new_rcu_qs(uint16_t nb_workers, struct rte_rcu_qsbr **qsv)
/* initialize QS variable for all workers */
if (rte_rcu_qsbr_init(*qsv, nb_workers) != 0) {
printf("RCU QSBR init failed\n");
(void)free(*qsv);
free(*qsv);
return -1;
}

Expand Down

0 comments on commit 7cd734d

Please sign in to comment.