• Reilly Grant's avatar
    Attach UsbContext to libusb_device(_handle) pointers · daa348fa
    Reilly Grant authored
    This change modifies ScopedLibusbDeviceRef and adds a new class
    ScopedLibusbDeviceHandle. This now explicitly own a reference to the
    UsbContext object (which reference counts a libusb_context) in addition
    to the libusb_device or libusb_device_handle they are wrapping.
    
    This resolves potential use-after-frees possible when posting tasks
    with a ScopedLibusbDeviceRef since the UsbService the task is being
    posted to could be destroyed before the task is executed. The
    libusb_device would then be released after its libusb_context has been
    destroyed.
    
    This is based on https://crrev.com/c/1131949 after I realized there
    where additional issues that needed to be addressed.
    
    Bug: 838947
    Change-Id: Idee02828bf615bd477033e585fffe03cf4d20595
    Reviewed-on: https://chromium-review.googlesource.com/1145910Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
    Commit-Queue: Reilly Grant <reillyg@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#577329}
    daa348fa
usb_device_impl.h 2.46 KB