Module Name: src
Committed By: bouyer
Date: Sat Jan 16 17:03:04 UTC 2010
Modified Files:
src/sys/dev/usb: usbdi.c
Log Message:
Fix leak of a usbd_xfer_handle when a interrupt pipe is aborted then
closed:
usbd_open_pipe_intr() allocates a usbd_xfer_handle for pipe->intrxfer.
Most usb device drivers using interrupt pipes call usbd_abort_pipe()
then usbd_close_pipe(), usbd_close_pipe() is supposed to free pipe->intrxfer.
But usbd_abort_pipe() calls [uoe]hci_device_intr_abort() which,
if the xfer aborted is pipe's intrxfer, sets pipe->intrxfer to NULL.
So usbd_close_pipe() can't free it and the usbd_xfer_handle is lost.
To fix this, in usbd_abort_pipe() remember the pipe->intrxfer's value
on entrie, and if it's different after usbd_ar_pipe(), call
usbd_free_xfer with the original value.
Confirmed to fix the memory leak on close() with umodem(4) and
uplcom(4).
To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/dev/usb/usbdi.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.126 src/sys/dev/usb/usbdi.c:1.127
--- src/sys/dev/usb/usbdi.c:1.126 Thu Nov 12 07:58:32 2009
+++ src/sys/dev/usb/usbdi.c Sat Jan 16 17:03:03 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: usbdi.c,v 1.126 2009/11/12 07:58:32 uebayasi Exp $ */
+/* $NetBSD: usbdi.c,v 1.127 2010/01/16 17:03:03 bouyer Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.28 1999/11/17 22:33:49 n_hibma Exp $ */
/*
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.126 2009/11/12 07:58:32 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.127 2010/01/16 17:03:03 bouyer Exp $");
#include "opt_compat_netbsd.h"
@@ -519,6 +519,7 @@
{
usbd_status err;
int s;
+ usbd_xfer_handle intrxfer = pipe->intrxfer;
#ifdef DIAGNOSTIC
if (pipe == NULL) {
@@ -529,6 +530,8 @@
s = splusb();
err = usbd_ar_pipe(pipe);
splx(s);
+ if (pipe->intrxfer != intrxfer)
+ usbd_free_xfer(intrxfer);
return (err);
}