payload_size -= sizeof(struct lttcomm_relayd_metadata_payload);
if (data_buffer_size < data_size) {
+ /* In case the realloc fails, we can free the memory */
+ char *tmp_data_ptr = data_buffer;
data_buffer = realloc(data_buffer, data_size);
if (!data_buffer) {
ERR("Allocating data buffer");
+ free(tmp_data_ptr);
ret = -1;
goto end;
}
" and last_seq %" PRIu64, stream_id, stream->prev_seq,
last_net_seq_num);
- if (stream->prev_seq == -1UL || stream->prev_seq <= last_net_seq_num) {
+ /* Avoid wrapping issue */
+ if (((int64_t) (stream->prev_seq - last_net_seq_num)) <= 0) {
/* Data has in fact been written and is available */
ret = 1;
} else {
data_size = be32toh(data_hdr.data_size);
if (data_buffer_size < data_size) {
+ char *tmp_data_ptr = data_buffer;
data_buffer = realloc(data_buffer, data_size);
if (!data_buffer) {
ERR("Allocating data buffer");
+ free(tmp_data_ptr);
ret = -1;
goto end_unlock;
}