[dpdk-dev] af_packet: fix possible memory leak
Commit Message
In rte_pmd_init_internals, we are mapping memory but not released
if error occure it could produce memoryleak.
Add unmmap function to release memory.
Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
---
lib/librte_pmd_af_packet/rte_eth_af_packet.c | 7 +++++++
1 file changed, 7 insertions(+)
Comments
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Daniel Mrzyglod
> Sent: Friday, December 19, 2014 4:02 PM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] af_packet: fix possible memory leak
>
> In rte_pmd_init_internals, we are mapping memory but not released
> if error occure it could produce memoryleak.
> Add unmmap function to release memory.
>
> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> ---
> lib/librte_pmd_af_packet/rte_eth_af_packet.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> index 236749b..93e6b6b 100644
> --- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> +++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> @@ -481,6 +481,11 @@ rte_pmd_init_internals(const char *name,
> if (*internals == NULL)
> goto error;
>
> + for (q = 0; q < nb_queues; q++) {
> + (*internals)->rx_queue[q].map = MAP_FAILED;
> + (*internals)->tx_queue[q].map = MAP_FAILED;
> + }
> +
> req = &((*internals)->req);
>
> req->tp_block_size = blocksize;
> @@ -682,6 +687,8 @@ error:
> rte_free(pci_dev);
> if (*internals) {
> for (q = 0; q < nb_queues; q++) {
> + munmap((*internals)->rx_queue[q].map,
> + 2 * req-
> >tp_block_size * req->tp_block_nr);
> if ((*internals)->rx_queue[q].rd)
> rte_free((*internals)->rx_queue[q].rd);
> if ((*internals)->tx_queue[q].rd)
> --
> 2.1.0
Acked-by: Michal Jastrzebski <michalx.k.jastrzebski@intel.com>
On Fri, Dec 19, 2014 at 04:01:36PM +0100, Daniel Mrzyglod wrote:
> In rte_pmd_init_internals, we are mapping memory but not released
> if error occure it could produce memoryleak.
> Add unmmap function to release memory.
>
> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> ---
> lib/librte_pmd_af_packet/rte_eth_af_packet.c | 7 +++++++
> 1 file changed, 7 insertions(+)
Acked-by: John W. Linville <linville@tuxdriver.com>
> > In rte_pmd_init_internals, we are mapping memory but not released
> > if error occure it could produce memoryleak.
> > Add unmmap function to release memory.
> >
> > Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
>
> Acked-by: John W. Linville <linville@tuxdriver.com>
Applied
Thanks
@@ -481,6 +481,11 @@ rte_pmd_init_internals(const char *name,
if (*internals == NULL)
goto error;
+ for (q = 0; q < nb_queues; q++) {
+ (*internals)->rx_queue[q].map = MAP_FAILED;
+ (*internals)->tx_queue[q].map = MAP_FAILED;
+ }
+
req = &((*internals)->req);
req->tp_block_size = blocksize;
@@ -682,6 +687,8 @@ error:
rte_free(pci_dev);
if (*internals) {
for (q = 0; q < nb_queues; q++) {
+ munmap((*internals)->rx_queue[q].map,
+ 2 * req->tp_block_size * req->tp_block_nr);
if ((*internals)->rx_queue[q].rd)
rte_free((*internals)->rx_queue[q].rd);
if ((*internals)->tx_queue[q].rd)