Skip to content

Commit

Permalink
[C] Make sure aeron_array_fast_unordered_remove is used correctly (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-adaptive committed Jan 28, 2025
1 parent 0c00753 commit e390850
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions aeron-client/src/main/c/aeron_client_conductor.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,10 @@ int aeron_client_conductor_check_lingering_resources(aeron_client_conductor_t *c
* Currently, only images are lingered and only until refcnt is 0. Even in the case of client timeout,
* etc. we let the application call aeron_close to clean up and shutdown the thread, etc.
*/
for (size_t i = 0, size = conductor->lingering_resources.length, last_index = size - 1; i < size; i++)
for (size_t size = conductor->lingering_resources.length, last_index = size - 1, i = size; i > 0; i--)
{
aeron_client_managed_resource_t *resource = &conductor->lingering_resources.array[i];
size_t index = i - 1;
aeron_client_managed_resource_t *resource = &conductor->lingering_resources.array[index];

if (AERON_CLIENT_TYPE_IMAGE == resource->type)
{
Expand All @@ -532,9 +533,10 @@ int aeron_client_conductor_check_lingering_resources(aeron_client_conductor_t *c
aeron_array_fast_unordered_remove(
(uint8_t *)conductor->lingering_resources.array,
sizeof(aeron_client_managed_resource_t),
i,
index,
last_index);
conductor->lingering_resources.length--;
last_index--;
work_count += 1;
}
}
Expand All @@ -547,18 +549,20 @@ int aeron_client_conductor_check_registering_resources(aeron_client_conductor_t
{
int work_count = 0;

for (size_t i = 0, size = conductor->registering_resources.length, last_index = size - 1; i < size; i++)
for (size_t size = conductor->registering_resources.length, last_index = size - 1, i = size; i > 0; i--)
{
aeron_client_registering_resource_t *resource = conductor->registering_resources.array[i].resource;
size_t index = i - 1;
aeron_client_registering_resource_t *resource = conductor->registering_resources.array[index].resource;

if (now_ns > resource->registration_deadline_ns)
{
aeron_array_fast_unordered_remove(
(uint8_t *)conductor->registering_resources.array,
sizeof(aeron_client_registering_resource_entry_t),
i,
index,
last_index);
conductor->registering_resources.length--;
last_index--;

AERON_SET_RELEASE(resource->registration_status, AERON_CLIENT_TIMEOUT_MEDIA_DRIVER);

Expand Down Expand Up @@ -1442,6 +1446,7 @@ void aeron_client_conductor_on_cmd_handler(void *clientd, void *item)
i,
last_index);
conductor->available_counter_handlers.length--;
break;
}
}
break;
Expand Down Expand Up @@ -1476,6 +1481,7 @@ void aeron_client_conductor_on_cmd_handler(void *clientd, void *item)
i,
last_index);
conductor->unavailable_counter_handlers.length--;
break;
}
}
break;
Expand Down Expand Up @@ -1508,6 +1514,7 @@ void aeron_client_conductor_on_cmd_handler(void *clientd, void *item)
i,
last_index);
conductor->close_handlers.length--;
break;
}
}
break;
Expand Down

0 comments on commit e390850

Please sign in to comment.