Skip to content

Memory error in trace buffer initialization #451

Open
@cmnrd

Description

When I compile the RTI (using gcc 14), then I get the following error:

/home/cmenard/projects/lf/lingua-franca/core/src/main/resources/lib/c/reactor-c/trace/impl/src/trace_impl.c: In function ‘start_trace’:
/home/cmenard/projects/lf/lingua-franca/core/src/main/resources/lib/c/reactor-c/trace/impl/src/trace_impl.c:155:57: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  155 |   trace->_lf_trace_buffer_size = (size_t*)calloc(sizeof(size_t), trace->_lf_number_of_trace_buffers + 1);
      |                                                         ^~~~~~
/home/cmenard/projects/lf/lingua-franca/core/src/main/resources/lib/c/reactor-c/trace/impl/src/trace_impl.c:155:57: note: earlier argument should specify number of elements, later size of each element

This hints at a bug in

trace->_lf_trace_buffer_size = (size_t*)calloc(sizeof(size_t), trace->_lf_number_of_trace_buffers + 1);
, which seems to have transposed arguments for the call to calloc.

I wanted to push a simple fix, but then I realized that there are more strange artifacts around this code. In particular:

  • Why is the array size to be allocated incremented by 1?
  • Why is trace->_lf_trace_buffer_size (the pointer to the newly allocated array) incremented by one in
    trace->_lf_trace_buffer_size++;
    ?
  • I could not find a call to free for this array.

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions