Skip to content

Commit

Permalink
[C] Fix potential leak in when adding stream interest to subscription…
Browse files Browse the repository at this point in the history
… by session.
  • Loading branch information
mjpt777 committed Mar 26, 2024
1 parent 53561c1 commit 93fc92a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions aeron-driver/src/main/c/aeron_data_packet_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,22 @@ int aeron_data_packet_dispatcher_add_subscription(aeron_data_packet_dispatcher_t
int aeron_data_packet_dispatcher_add_subscription_by_session(
aeron_data_packet_dispatcher_t *dispatcher, int32_t stream_id, int32_t session_id)
{
aeron_data_packet_dispatcher_stream_interest_t *stream_interest;
aeron_data_packet_dispatcher_stream_interest_t *stream_interest = aeron_int64_to_ptr_hash_map_get(
&dispatcher->session_by_stream_id_map, stream_id);

if ((stream_interest = aeron_int64_to_ptr_hash_map_get(&dispatcher->session_by_stream_id_map, stream_id)) == NULL)
if (NULL == stream_interest)
{
if (aeron_alloc((void **)&stream_interest, sizeof(aeron_data_packet_dispatcher_stream_interest_t)) < 0 ||
aeron_data_packet_dispatcher_stream_interest_init(stream_interest, false) < 0 ||
if (aeron_alloc((void **)&stream_interest, sizeof(aeron_data_packet_dispatcher_stream_interest_t)) < 0)
{
AERON_APPEND_ERR("%s", "Failed to allocate stream_interest");
return -1;
}

if (aeron_data_packet_dispatcher_stream_interest_init(stream_interest, false) < 0 ||
aeron_int64_to_ptr_hash_map_put(&dispatcher->session_by_stream_id_map, stream_id, stream_interest) < 0)
{
AERON_APPEND_ERR("%s", "Failed to add stream_interest to session_by_stream_id_map");
aeron_free(stream_interest);
return -1;
}
}
Expand Down

0 comments on commit 93fc92a

Please sign in to comment.