Skip to content

Commit db0e182

Browse files
committed
Fix bugs in sync library error handling
fnusb_open_subdevices checked for camera==NULL or res < 0 before jumping to the failure case. If camera was NULL but res was not 0, the function would return 0 indicating success. This occurs when a kinect is not plugged into the PC. Forcing res to be negative when the camera == NULL case allows the failure to open a device to propagate through an application. alloc_kinect in freenect_sync has a check for if freenect_open_device fails, but the logic is incorrect. freenect_open_device returns 0 on success and < 0 on error, so adding a check to see if the return is < 0 corrects detection of the failure case. Signed-off-by: Rich Mattes <[email protected]>
1 parent 9e98a0b commit db0e182

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/usb_libusb10.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
465465
}
466466

467467
if (res < 0 || camera == NULL) {
468+
res = -1;
468469
goto failure;
469470
}
470471

wrappers/c_sync/libfreenect_sync.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static int change_depth_format(sync_kinect_t *kinect, freenect_resolution res, f
249249
static sync_kinect_t *alloc_kinect(int index)
250250
{
251251
sync_kinect_t *kinect = (sync_kinect_t*)malloc(sizeof(sync_kinect_t));
252-
if (freenect_open_device(ctx, &kinect->dev, index)) {
252+
if (freenect_open_device(ctx, &kinect->dev, index) < 0) {
253253
free(kinect);
254254
return NULL;
255255
}

0 commit comments

Comments
 (0)