Skip to content

potential memory leak in pipeline::start method (callback overloads) #3873

@tomaszmi

Description

@tomaszmi

Required Info
Camera Model any
Firmware Version n.a.
Operating System & Version n.a.
Kernel Version (Linux Only) n.a.
Platform n.a.
SDK Version master
Language C++
Segment core

Issue Description

The code inside pipeline::start methods (overloads accepting callback) is dangerous and could be a potential source of memory leak:

        template<class S>
        pipeline_profile start(const config& config, S callback)
        {
            rs2_error* e = nullptr;
            auto p = std::shared_ptr<rs2_pipeline_profile>(
                rs2_pipeline_start_with_config_and_callback_cpp(_pipeline.get(), config.get().get(), new frame_callback<S>(callback), &e),
                rs2_delete_pipeline_profile);

            error::handle(e);
            return pipeline_profile(p);
        }

Problem statement:
The ownership of the memory allocated for the frame_callback object is passed to rs2_pipeline_start_with_callback_cpp function however there are control flows where the memory will not be properly released:

  • argument evaluation order is unspecified and config.get() may throw an exception while memory is already allocated
  • there is a case inside the rs2_pipeline_start_with_config_and_callback_cpp implementation when an exception may happen before ownership of the passed memory is accepted.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions