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

clang-tidy: potential leak in 2.21.0 sensor::start #4447

Closed
pinver opened this issue Jul 17, 2019 · 2 comments
Closed

clang-tidy: potential leak in 2.21.0 sensor::start #4447

pinver opened this issue Jul 17, 2019 · 2 comments
Labels

Comments

@pinver
Copy link

pinver commented Jul 17, 2019

This seems similar to issue #3873

       template<class T>
        void start(T callback) const
        {
            rs2_error* e = nullptr;
            rs2_start_cpp(_sensor.get(), new frame_callback<T>(std::move(callback)), &e);
            error::handle(e);
        }

clang-tidy reports:

<snip>/librealsense2/hpp/rs_sensor.hpp:190:13: warning: Potential memory leak [clang-analyzer-cplusplus.NewDeleteLeaks]
            error::handle(e);
            ^
<snip> realsense/realsense_interface.cc:123:3: note: Calling 'sensor::start'
  realsense_sensor_.start(frame_queue);
  ^
<snip>/librealsense2/hpp/rs_sensor.hpp:189:42: note: Memory is allocated
            rs2_start_cpp(_sensor.get(), new frame_callback<T>(std::move(callback)), &e);
                                         ^
<snip>/librealsense2/hpp/rs_sensor.hpp:190:13: note: Potential memory leak
            error::handle(e);
            ^
@dorodnic dorodnic added the bug label Jul 19, 2019
@radfordi
Copy link
Contributor

Are you saying this is an actual leak or just that clang-tidy thinks there is an error? It looks to me like we initialize the shared_ptr with the correct destructor immediately and that nothing can throw in the mean time. Am I missing something?

void rs2_start_cpp(const rs2_sensor* sensor, rs2_frame_callback* callback, rs2_error** error) BEGIN_API_CALL                                                                                                                                                                                                                          const rs2_context *context  context
{                                                                                                                                                                                                                                                                                                                     rs2_devices_changed_callback_ptr callback  callback
    VALIDATE_NOT_NULL(sensor);                                                                                                                                                                                                                                                                                                                           void *user  user
    VALIDATE_NOT_NULL(callback);
    sensor->sensor->start({ callback, [](rs2_frame_callback* p) { p->release(); } });
}
HANDLE_EXCEPTIONS_AND_RETURN(, sensor, callback)

@RealSenseSupport
Copy link
Collaborator

Just wondering if this is still an issue with the recent SDK release.
Thank you and the case will be closed unless otherwise.

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

No branches or pull requests

5 participants