Skip to content

Commit

Permalink
fix(auto-heartbeat): memory issues with member removal
Browse files Browse the repository at this point in the history
Fix issues because of which library crashes in attempt to move memory into overlapping region.
  • Loading branch information
parfeon committed Oct 14, 2024
1 parent c94385b commit 0095a45
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/pbcc_subscribe_event_engine_effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void make_subscribe_request_(
size_t token_len = strlen(ctx->cursor.timetoken);
memcpy(pb->core.timetoken, ctx->cursor.timetoken, token_len);
pb->core.timetoken[token_len] = '\0';
if (ctx->cursor.region > 0) { pb->core.region = ctx->cursor.region; }
pb->core.region = ctx->cursor.region;
pbpal_mutex_unlock(pb->monitor);

struct pubnub_subscribe_v2_options opts = pubnub_subscribe_v2_defopts();
Expand Down
1 change: 1 addition & 0 deletions core/pbcc_subscribe_event_engine_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ pbcc_subscribe_ee_context_t* pbcc_subscribe_ee_context_alloc_(
context->channels = NULL;
context->channel_groups = NULL;
context->send_heartbeat = false;
context->cursor = pubnub_subscribe_cursor(NULL);
if (NULL != channels && NULL != *channels)
context->channels = pbcc_ee_data_alloc(*channels, free);
if (NULL != channel_groups && NULL != *channel_groups) {
Expand Down
4 changes: 2 additions & 2 deletions core/pbcc_subscribe_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ enum pubnub_res pbcc_subscribe_v2_prep(struct pbcc_context* p,
p->timetoken[1] = '\0';
tr = NULL;
}
else {
else if (p->region > 0) {
snprintf(region_str, sizeof region_str, "%d", p->region);
tr = region_str;
}
} else { tr = NULL; }
p->http_content_len = 0;
p->msg_ofs = p->msg_end = 0;

Expand Down
2 changes: 1 addition & 1 deletion core/pubnub_subscribe_event_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ enum pubnub_res pubnub_subscription_set_remove_(
/** Preventing `pbhash_set` (set->subscriptions) from freeing `sub`. */
pubnub_subscription_t* stored_subscription = (pubnub_subscription_t*)
pbhash_set_element(set->subscriptions, (*sub)->entity->id.ptr);
bool same_object = stored_subscription == *sub;
const bool same_object = stored_subscription == *sub;
subscription_reference_count_update_(stored_subscription, true);
pbhash_set_remove(set->subscriptions,
(void**)&stored_subscription->entity->id.ptr,
Expand Down
3 changes: 1 addition & 2 deletions core/samples/subscribe_event_engine_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ int main()
pubnub_res_2_string(rslt));

/** Wait for messages published to one of the channels (manual). */
// wait_seconds(60);
wait_seconds(15);
wait_seconds(60);


/**
Expand Down
2 changes: 1 addition & 1 deletion lib/pbstr_remove_from_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void remove_member(char* list, const char* member, size_t member_len)
}
if (((size_t)(l_ch_end - l_start) == member_len) &&
(memcmp(l_start, member, member_len) == 0)) {
size_t rest = l_end - l_ch_end + 1;
const size_t rest = l_end != l_ch_end ? l_end - (l_ch_end + 1) : 0;
if (rest > 1) {
/* Moves everything behind next comma including string end */
memmove(l_start, l_ch_end + 1, rest);
Expand Down

0 comments on commit 0095a45

Please sign in to comment.