Skip to content

Commit

Permalink
Use calloc instead of malloc to initialize the memory to 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
erlingrj committed Dec 18, 2023
1 parent c2b3fae commit 37a1249
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/federated/RTI/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ int main(int argc, const char* argv[]) {
// Allocate memory for the federates
rti.base.scheduling_nodes = (scheduling_node_t**)calloc(rti.base.number_of_scheduling_nodes, sizeof(scheduling_node_t*));
for (uint16_t i = 0; i < rti.base.number_of_scheduling_nodes; i++) {
federate_info_t *fed_info = (federate_info_t *) malloc(sizeof(federate_info_t));
federate_info_t *fed_info = (federate_info_t *) calloc(1, sizeof(federate_info_t));
initialize_federate(fed_info, i);
rti.base.scheduling_nodes[i] = (scheduling_node_t *) fed_info;
}
Expand Down
2 changes: 2 additions & 0 deletions core/federated/RTI/rti_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ void update_min_delays_upstream(scheduling_node_t* node) {

// Put the results onto the node's struct.
node->num_min_delays = count;
// FIXME: What should the newly allocated `min_delays` be initialized to?
// currently it could be any value.
node->min_delays = (minimum_delay_t*)malloc(count * sizeof(minimum_delay_t));
LF_PRINT_DEBUG("++++ Node %hu(is in ZDC: %d\n", node->id, node->flags & IS_IN_ZERO_DELAY_CYCLE);
int k = 0;
Expand Down
4 changes: 2 additions & 2 deletions core/federated/RTI/rti_local.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static rti_local_t * rti_local;
lf_mutex_t rti_mutex;

void initialize_local_rti(environment_t *envs, int num_envs) {
rti_local = (rti_local_t*)malloc(sizeof(rti_local_t));
rti_local = (rti_local_t*)calloc(1, sizeof(rti_local_t));
LF_ASSERT(rti_local, "Out of memory");

initialize_rti_common(&rti_local->base);
Expand All @@ -47,7 +47,7 @@ void initialize_local_rti(environment_t *envs, int num_envs) {
// Allocate memory for the enclave_info objects
rti_local->base.scheduling_nodes = (scheduling_node_t**)calloc(num_envs, sizeof(scheduling_node_t*));
for (int i = 0; i < num_envs; i++) {
enclave_info_t *enclave_info = (enclave_info_t *) malloc(sizeof(enclave_info_t));
enclave_info_t *enclave_info = (enclave_info_t *) calloc(1, sizeof(enclave_info_t));
initialize_enclave_info(enclave_info, i, &envs[i]);
rti_local->base.scheduling_nodes[i] = (scheduling_node_t *) enclave_info;

Expand Down

0 comments on commit 37a1249

Please sign in to comment.