Skip to content

Commit

Permalink
Fix memory and resource leak via user callback management
Browse files Browse the repository at this point in the history
Remove unused variables
  • Loading branch information
ev-mp committed Aug 18, 2019
1 parent 897b92f commit a0c51a1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/pipeline/resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ namespace librealsense

// Unpack the data returned by assign
std::map<int, stream_profiles> dev_to_profiles;
std::map<index_type, sensor_interface*> stream_to_dev;
std::map<index_type, std::shared_ptr<stream_profile_interface>> stream_to_profile;

std::map<int, sensor_interface*> sensors_map;
Expand All @@ -303,7 +302,6 @@ namespace librealsense
for (auto && kvp : mapping) {
dev_to_profiles[kvp.first].push_back(kvp.second);
index_type idx{ kvp.second->get_stream_type(), kvp.second->get_stream_index() };
stream_to_dev.emplace(idx, sensors_map.at(kvp.first));
stream_to_profile[idx] = kvp.second;
}

Expand Down
16 changes: 8 additions & 8 deletions src/win7/win7-uvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,14 @@ namespace librealsense
winusb_free_formats(formats);
callback_context *context = new callback_context();
context->_callback = callback;
context->_this = this;
context->_profile = profile;
auto sts = winusb_start_streaming(_device.get(), &ctrl, internal_winusb_uvc_callback, context, 0);
if(sts != UVC_SUCCESS)
throw std::runtime_error("Failed to start streaming!");
_cb_context = std::make_shared<callback_context>();
_cb_context->_callback = callback;
_cb_context->_profile = profile;
_cb_context->_this = this;
auto sts = winusb_start_streaming(_device.get(), &ctrl, internal_winusb_uvc_callback, _cb_context.get(), 0);
if(sts != UVC_SUCCESS)
throw std::runtime_error("Failed to start streaming!");
}
void win7_uvc_device::stream_on(std::function<void(const notification& n)> error_handler)
Expand Down
2 changes: 2 additions & 0 deletions src/win7/win7-uvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace librealsense
namespace platform
{
class win7_backend;
struct callback_context;

struct profile_and_callback
{
Expand Down Expand Up @@ -99,6 +100,7 @@ namespace librealsense
std::mutex _streams_mutex;

std::shared_ptr<const win7_backend> _backend;
std::shared_ptr<callback_context> _cb_context;

std::string _location;
usb_spec _device_usb_spec;
Expand Down
1 change: 0 additions & 1 deletion src/win7/winusb_uvc/winusb_uvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,6 @@ void winusb_uvc_stream_close(winusb_uvc_stream_handle_t *strmh)

DL_DELETE(strmh->devh->streams, strmh);

free(strmh->user_ptr);
free(strmh);
}

Expand Down
2 changes: 1 addition & 1 deletion src/win7/winusb_uvc/winusb_uvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ struct winusb_uvc_stream_handle {

std::thread cb_thread;
winusb_uvc_frame_callback_t *user_cb;
void *user_ptr;
void *user_ptr; // User-allocated memory
enum uvc_frame_format frame_format;
};

Expand Down

0 comments on commit a0c51a1

Please sign in to comment.