Skip to content

Commit 6c66a00

Browse files
committed
Check for a cancelled URB before attempting to reply
1 parent b6c3164 commit 6c66a00

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

app/src/main/java/org/cgutman/usbip/service/UsbIpService.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ public void run() {
483483
System.out.printf("Bulk transfer complete with %d bytes (wanted %d)\n",
484484
res, msg.transferBufferLength);
485485
}
486+
487+
if (!context.activeMessages.remove(msg)) {
488+
// Somebody cancelled the URB, return without responding
489+
return;
490+
}
486491

487492
if (res < 0) {
488493
// If the request failed, let's see if the device is still around
@@ -500,7 +505,6 @@ public void run() {
500505
reply.status = ProtoDefs.ST_OK;
501506
}
502507

503-
context.activeMessages.remove(msg);
504508
sendReply(s, reply, reply.status);
505509
}
506510
else if (selectedEndpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) {
@@ -529,6 +533,11 @@ else if (selectedEndpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) {
529533
System.out.printf("Interrupt transfer complete with %d bytes (wanted %d)\n",
530534
res, msg.transferBufferLength);
531535
}
536+
537+
if (!context.activeMessages.remove(msg)) {
538+
// Somebody cancelled the URB, return without responding
539+
return;
540+
}
532541

533542
if (res < 0) {
534543
reply.status = res;
@@ -546,7 +555,6 @@ else if (selectedEndpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) {
546555
reply.status = ProtoDefs.ST_OK;
547556
}
548557

549-
context.activeMessages.remove(msg);
550558
sendReply(s, reply, reply.status);
551559
}
552560
else {
@@ -617,6 +625,11 @@ public void submitUrbRequest(Socket s, UsbIpSubmitUrb msg) {
617625
res = 0;
618626
}
619627

628+
if (!context.activeMessages.remove(msg)) {
629+
// Somebody cancelled the URB, return without responding
630+
return;
631+
}
632+
620633
if (res < 0) {
621634
// If the request failed, let's see if the device is still around
622635
UsbDevice dev = getDevice(deviceId);
@@ -633,7 +646,6 @@ public void submitUrbRequest(Socket s, UsbIpSubmitUrb msg) {
633646
reply.status = ProtoDefs.ST_OK;
634647
}
635648

636-
context.activeMessages.remove(msg);
637649
sendReply(s, reply, reply.status);
638650
}
639651
else {

0 commit comments

Comments
 (0)