Merge pull request #3135 from geky/lwip-fix-cyclic-buffer-leak

lwip - Fix memory leak in k64f cyclic-buffer overflow
pull/3184/head
Sam Grove 2016-11-01 14:12:24 -05:00 committed by GitHub
commit fcfc7b46a7
1 changed files with 11 additions and 13 deletions

View File

@ -102,24 +102,22 @@ static void update_read_buffer(uint8_t *buf)
*/
static void k64f_tx_reclaim(struct k64f_enetdata *k64f_enet)
{
uint8_t i = 0 ;
/* Get exclusive access */
sys_mutex_lock(&k64f_enet->TXLockMutex);
i = k64f_enet->tx_consume_index;
// Traverse all descriptors, looking for the ones modified by the uDMA
while((i != k64f_enet->tx_produce_index) && (!(g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK))) {
pbuf_free(tx_buff[i]);
while((k64f_enet->tx_consume_index != k64f_enet->tx_produce_index) &&
(!(g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK))) {
pbuf_free(tx_buff[k64f_enet->tx_consume_index % ENET_TX_RING_LEN]);
if (g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK)
g_handle.txBdDirty = g_handle.txBdBase;
else
g_handle.txBdDirty++;
i = (i + 1) % ENET_TX_RING_LEN;
k64f_enet->tx_consume_index += 1;
osSemaphoreRelease(k64f_enet->xTXDCountSem.id);
}
k64f_enet->tx_consume_index = i;
/* Restore access */
sys_mutex_unlock(&k64f_enet->TXLockMutex);
}
@ -524,17 +522,17 @@ static err_t k64f_low_level_output(struct netif *netif, struct pbuf *p)
dst += q->len;
}
/* Wait until a descriptor is available for the transfer. */
/* THIS WILL BLOCK UNTIL THERE ARE A DESCRIPTOR AVAILABLE */
while (g_handle.txBdCurrent->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK)
osSemaphoreWait(k64f_enet->xTXDCountSem.id, osWaitForever);
/* Check if a descriptor is available for the transfer. */
int32_t count = osSemaphoreWait(k64f_enet->xTXDCountSem.id, 0);
if (count < 1)
return ERR_BUF;
/* Get exclusive access */
sys_mutex_lock(&k64f_enet->TXLockMutex);
/* Save the buffer so that it can be freed when transmit is done */
tx_buff[k64f_enet->tx_produce_index] = temp_pbuf;
k64f_enet->tx_produce_index = (k64f_enet->tx_produce_index + 1) % ENET_TX_RING_LEN;
tx_buff[k64f_enet->tx_produce_index % ENET_TX_RING_LEN] = temp_pbuf;
k64f_enet->tx_produce_index += 1;
/* Setup transfers */
g_handle.txBdCurrent->buffer = psend;