Closed s-trinh closed 3 years ago
Interesting, we need to check these. Thank you for the report
I tested the latest development version on ubuntu 16.04. I found some memory leaks ("blocks are indirectly lost", "blocks are still reachable", etc.) but no "Conditional jump or move depends on uninitialised value(s)". errors. Tested with both v4l and rsusb backends. My guess is that this issue was fixed with #8875 but maybe it was something else. I opened an internal ticket - LRS-317 - to fix the existing valgrind errors and warnings.
I have at least a similar issue. Here is the valgrind (memcheck) backtrace collected with --track-origins=yes
==15861== Conditional jump or move depends on uninitialised value(s)
==15861== at 0x957DBE8: librealsense::md_attribute_parser<librealsense::md_depth_control, unsigned int, librealsense::md_depth_control_attributes>::is_attribute_valid(librealsense::md_depth_control const*) const (metadata-parser.h:152)
==15861== by 0x957C09A: librealsense::md_attribute_parser<librealsense::md_depth_control, unsigned int, librealsense::md_depth_control_attributes>::supports(librealsense::frame const&) const (metadata-parser.h:141)
==15861== by 0x9C970C0: librealsense::frame::supports_frame_metadata(rs2_frame_metadata_value const&) const (frame.cpp:144)
==15861== by 0x9537E74: librealsense::ds5_md_attribute_actual_fps::get(librealsense::frame const&) const (metadata-parser.h:352)
==15861== by 0x9C96E1C: librealsense::frame::get_frame_metadata(rs2_frame_metadata_value const&) const (frame.cpp:117)
==15861== by 0x9C5974B: librealsense::timestamp_composite_matcher::update_last_arrived(librealsense::frame_holder&, librealsense::matcher*) (sync.cpp:565)
==15861== by 0x9C56048: librealsense::composite_matcher::dispatch(librealsense::frame_holder, librealsense::syncronization_environment const&) (sync.cpp:147)
==15861== by 0x9C5609B: librealsense::composite_matcher::dispatch(librealsense::frame_holder, librealsense::syncronization_environment const&) (sync.cpp:148)
==15861== by 0x98EF62B: librealsense::syncer_process_unit::syncer_process_unit(std::initializer_list<std::shared_ptr<librealsense::bool_option> >, bool)::{lambda(librealsense::frame_holder, librealsense::synthetic_source_interface*)#2}::operator()(librealsense::frame_holder, librealsense::synthetic_source_interface*) const (syncer-processing-block.cpp:63)
==15861== by 0x98F36A5: librealsense::internal_frame_processor_callback<librealsense::syncer_process_unit::syncer_process_unit(std::initializer_list<std::shared_ptr<librealsense::bool_option> >, bool)::{lambda(librealsense::frame_holder, librealsense::synthetic_source_interface*)#2}>::on_frame(rs2_frame*, rs2_source*) (processing.h:67)
==15861== by 0x98DD75F: librealsense::processing_block::invoke(librealsense::frame_holder) (synthetic-stream.cpp:43)
==15861== by 0x99B344E: librealsense::pipeline::pipeline::get_callback(std::vector<int, std::allocator<int> >)::{lambda(librealsense::frame_holder)#3}::operator()(librealsense::frame_holder) const (pipeline.cpp:215)
==15861== by 0x99BB89B: librealsense::internal_frame_callback<librealsense::pipeline::pipeline::get_callback(std::vector<int, std::allocator<int> >)::{lambda(librealsense::frame_holder)#3}>::on_frame(rs2_frame*) (types.h:763)
==15861== by 0x9C0ABBE: librealsense::synthetic_sensor::start(std::shared_ptr<rs2_frame_callback>)::{lambda(librealsense::frame_holder)#1}::operator()(librealsense::frame_holder) const (sensor.cpp:1586)
==15861== by 0x9C12C85: librealsense::internal_frame_callback<librealsense::synthetic_sensor::start(std::shared_ptr<rs2_frame_callback>)::{lambda(librealsense::frame_holder)#1}>::on_frame(rs2_frame*) (types.h:763)
==15861== by 0x9C4AFE1: librealsense::frame_source::invoke_callback(librealsense::frame_holder) const (source.cpp:123)
==15861== by 0x98E0CCC: librealsense::synthetic_source::frame_ready(librealsense::frame_holder) (synthetic-stream.cpp:319)
==15861== by 0x9B958AA: rs2_synthetic_frame_ready (rs.cpp:1776)
==15861== by 0x98E95FB: rs2::frame_source::frame_ready(rs2::frame) const (rs_processing.hpp:102)
==15861== by 0x98DDDD2: librealsense::generic_processing_block::generic_processing_block(char const*)::{lambda(rs2::frame, rs2::frame_source const&)#1}::operator()(rs2::frame, rs2::frame_source const&) const (synthetic-stream.cpp:95)
==15861== by 0x98E8C12: rs2::frame_processor_callback<librealsense::generic_processing_block::generic_processing_block(char const*)::{lambda(rs2::frame, rs2::frame_source const&)#1}>::on_frame(rs2_frame*, rs2_source*) (rs_processing.hpp:128)
==15861== by 0x98DD75F: librealsense::processing_block::invoke(librealsense::frame_holder) (synthetic-stream.cpp:43)
==15861== by 0x9C0AD90: librealsense::synthetic_sensor::start(std::shared_ptr<rs2_frame_callback>)::{lambda(librealsense::frame_holder)#2}::operator()(librealsense::frame_holder) const (sensor.cpp:1611)
==15861== by 0x9C12BC9: librealsense::internal_frame_callback<librealsense::synthetic_sensor::start(std::shared_ptr<rs2_frame_callback>)::{lambda(librealsense::frame_holder)#2}>::on_frame(rs2_frame*) (types.h:763)
==15861== by 0x9C4AFE1: librealsense::frame_source::invoke_callback(librealsense::frame_holder) const (source.cpp:123)
==15861== by 0x9BFE159: librealsense::uvc_sensor::open(std::vector<std::shared_ptr<librealsense::stream_profile_interface>, std::allocator<std::shared_ptr<librealsense::stream_profile_interface> > > const&)::{lambda(librealsense::platform::stream_profile, librealsense::platform::frame_object, std::function<void ()>)#1}::operator()(librealsense::platform::stream_profile, librealsense::platform::frame_object, std::function<void ()>) (sensor.cpp:433)
==15861== by 0x9C0CF9E: std::_Function_handler<void (librealsense::platform::stream_profile, librealsense::platform::frame_object, std::function<void ()>), librealsense::uvc_sensor::open(std::vector<std::shared_ptr<librealsense::stream_profile_interface>, std::allocator<std::shared_ptr<librealsense::stream_profile_interface> > > const&)::{lambda(librealsense::platform::stream_profile, librealsense::platform::frame_object, std::function<void ()>)#1}>::_M_invoke(std::_Any_data const&, librealsense::platform::stream_profile&&, librealsense::platform::frame_object&&, std::function<void ()>&&) (std_function.h:316)
==15861== by 0x9888481: std::function<void (librealsense::platform::stream_profile, librealsense::platform::frame_object, std::function<void ()>)>::operator()(librealsense::platform::stream_profile, librealsense::platform::frame_object, std::function<void ()>) const (std_function.h:706)
==15861== by 0x9A432EE: librealsense::platform::v4l_uvc_device::poll() (backend-v4l2.cpp:1102)
==15861== by 0x9A455D7: librealsense::platform::v4l_uvc_device::capture_loop() (backend-v4l2.cpp:1469)
==15861== by 0x9A4157A: librealsense::platform::v4l_uvc_device::stream_on(std::function<void (librealsense::notification const&)>)::{lambda()#1}::operator()() const (backend-v4l2.cpp:809)
==15861== by 0x9A4A618: void std::__invoke_impl<void, librealsense::platform::v4l_uvc_device::stream_on(std::function<void (librealsense::notification const&)>)::{lambda()#1}>(std::__invoke_other, librealsense::platform::v4l_uvc_device::stream_on(std::function<void (librealsense::notification const&)>)::{lambda()#1}&&) (invoke.h:60)
==15861== by 0x9A4910C: std::__invoke_result<librealsense::platform::v4l_uvc_device::stream_on(std::function<void (librealsense::notification const&)>)::{lambda()#1}>::type std::__invoke<librealsense::platform::v4l_uvc_device::stream_on(std::function<void (librealsense::notification const&)>)::{lambda()#1}>(std::__invoke_result&&, (librealsense::platform::v4l_uvc_device::stream_on(std::function<void (librealsense::notification const&)>)::{lambda()#1}&&)...) (invoke.h:95)
==15861== by 0x9A4D9F7: decltype (__invoke((_S_declval<0ul>)())) std::thread::_Invoker<std::tuple<librealsense::platform::v4l_uvc_device::stream_on(std::function<void (librealsense::notification const&)>)::{lambda()#1}> >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (thread:234)
==15861== by 0x9A4D9B3: std::thread::_Invoker<std::tuple<librealsense::platform::v4l_uvc_device::stream_on(std::function<void (librealsense::notification const&)>)::{lambda()#1}> >::operator()() (thread:243)
==15861== by 0x9A4D983: std::thread::_State_impl<std::thread::_Invoker<std::tuple<librealsense::platform::v4l_uvc_device::stream_on(std::function<void (librealsense::notification const&)>)::{lambda()#1}> > >::_M_run() (thread:186)
==15861== by 0xAF7B6DE: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25)
==15861== by 0x56EB6DA: start_thread (pthread_create.c:463)
==15861== by 0x5A2471E: clone (clone.S:95)
==15861== Uninitialised value was created by a stack allocation
==15861== at 0x9BFC61B: librealsense::sensor_base::generate_frame_from_data(librealsense::platform::frame_object const&, librealsense::frame_timestamp_reader*, double const&, unsigned long long const&, std::shared_ptr<librealsense::stream_profile_interface>) (sensor.cpp:267)
==15861==
Interestingly this issue only shows up in valgrind within a bigger codebase, so far I have not managed to recreate it with a minimal example.
After a little bit of investigation, my guess was that the problem lies here in the frame additional_data constructor
struct frame_additional_data : frame_header
{
...
std::array<uint8_t, MAX_META_DATA_SIZE> metadata_blob;
...
frame_additional_data( rs2_time_t in_timestamp,
unsigned long long in_frame_number,
rs2_time_t in_system_time,
uint8_t md_size,
const uint8_t * md_buf,
rs2_time_t backend_time,
rs2_time_t last_timestamp,
unsigned long long last_frame_number,
bool in_is_blocking,
float in_depth_units = 0,
uint32_t transmitted_size = 0 )
: frame_header( in_timestamp, in_frame_number, in_system_time, backend_time )
, metadata_size( md_size )
, last_timestamp( last_timestamp )
, last_frame_number( last_frame_number )
, is_blocking( in_is_blocking )
, depth_units( in_depth_units )
, raw_size( transmitted_size )
{
// Copy up to 255 bytes to preserve metadata as raw data
if( metadata_size )
std::copy( md_buf, md_buf + std::min( md_size, MAX_META_DATA_SIZE ), metadata_blob.begin() );
}
}
std::copy only initializes part of the buffer metadata_blob. In use this then later shows up in valgrind. In sensors.hpp as a stack allocation:
std::shared_ptr<frame> sensor_base::generate_frame_from_data(const platform::frame_object& fo,
frame_timestamp_reader* timestamp_reader,
const rs2_time_t& last_timestamp,
const unsigned long long& last_frame_number,
std::shared_ptr<stream_profile_interface> profile)
{
....
frame_additional_data additional_data(0,
0,
system_time,
static_cast<uint8_t>(fo.metadata_size),
(const uint8_t*)fo.metadata,
fo.backend_time,
last_timestamp,
last_frame_number,
false,
0,
(uint32_t)fo.frame_size);
if (_metadata_modifier)
_metadata_modifier(additional_data);
fr->additional_data = additional_data;
....
After adding std::array::fill to the constructor
metadata_blob.fill(0);
if( metadata_size )
std::copy( md_buf, md_buf + std::min( md_size, MAX_META_DATA_SIZE ), metadata_blob.begin() );
valgrind is completely satisfied. However the call still fails, with the same error:
RealSense error calling rs2_get_frame_metadata
It seems to work now, but i'm not sure if this actually fixed the underlying issue.
Version info:
Issue Description
Maybe it is just some false positives but I get
Conditional jump or move depends on uninitialised value(s)
errors with the following code and latest librealsense:Log: