Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tomaszmi opened this issue Apr 30, 2019 · 1 comment
Closed

Comments

@tomaszmi
Copy link

tomaszmi commented Apr 30, 2019


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.
@dorodnic
Copy link
Contributor

dorodnic commented May 5, 2019

Hi @tomaszmi
Thanks, your point is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants