Commit 03b3afb8 authored by Jussi Kivilinna's avatar Jussi Kivilinna Committed by Pekka Niemimaa
Browse files

cdcacm: fix memory leak in unbind



Freeing write requests seemingly worked, but since IN endpoint was freed
before write requests, 'priv->epbulkin' was NULL and cdcacm_freereq for
write requests as result was NOP.

Change order of freeing and add debug assert to cdcacm_freereq to make
such memory leaks more noticeable.
Signed-off-by: default avatarJussi Kivilinna <jussi.kivilinna@haltian.com>
(cherry picked from commit 215b7fb129621d6fd7b7de40a34d737e69cecf8a)
parent ab8c2bd7
......@@ -553,11 +553,17 @@ static struct usbdev_req_s *cdcacm_allocreq(FAR struct usbdev_ep_s *ep,
static void cdcacm_freereq(FAR struct usbdev_ep_s *ep,
FAR struct usbdev_req_s *req)
{
if (req != NULL && req->buf != NULL)
{
DEBUGASSERT(ep != NULL);
}
if (ep != NULL && req != NULL)
{
if (req->buf != NULL)
{
EP_FREEBUFFER(ep, req->buf);
req->buf = NULL;
}
EP_FREEREQ(ep, req);
}
......@@ -1151,14 +1157,6 @@ static void cdcacm_unbind(FAR struct usbdevclass_driver_s *driver,
priv->epintin = NULL;
}
/* Free the bulk IN endpoint */
if (priv->epbulkin)
{
DEV_FREEEP(dev, priv->epbulkin);
priv->epbulkin = NULL;
}
/* Free the pre-allocated control request */
if (priv->ctrlreq != NULL)
......@@ -1209,6 +1207,14 @@ static void cdcacm_unbind(FAR struct usbdevclass_driver_s *driver,
DEBUGASSERT(priv->nwrq == 0);
irqrestore(flags);
/* Free the bulk IN endpoint */
if (priv->epbulkin)
{
DEV_FREEEP(dev, priv->epbulkin);
priv->epbulkin = NULL;
}
/* Clear out all data in the circular buffer */
priv->serdev.xmit.head = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment