From: wangyunjian <wangyunjian@huawei.com>
To: <dev@dpdk.org>
Cc: <linville@tuxdriver.com>, <jerry.lilijun@huawei.com>,
<xudingke@huawei.com>, Yunjian Wang <wangyunjian@huawei.com>,
<stable@dpdk.org>
Subject: [dpdk-dev] [PATCH 2/3] net/af_packet: fix mem leak on init failure
Date: Mon, 6 Jul 2020 20:27:51 +0800 [thread overview]
Message-ID: <e83ef7df3a4361264839a39f649e02d6606f11e5.1594037787.git.wangyunjian@huawei.com> (raw)
In-Reply-To: <cover.1594037787.git.wangyunjian@huawei.com>
From: Yunjian Wang <wangyunjian@huawei.com>
Add missing code to free memory when the device initialization fails.
Fixes: ccd37d341e8d ("net/af_packet: remove queue number limitation")
Fixes: 5f19dee604ed ("drivers/net: do not use private ethdev data")
Cc: stable@dpdk.org
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
drivers/net/af_packet/rte_eth_af_packet.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index 361b5d5..be3fabb 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -637,9 +637,7 @@ struct pmd_internals {
sizeof(struct pkt_tx_queue),
0, numa_node);
if (!(*internals)->rx_queue || !(*internals)->tx_queue) {
- rte_free((*internals)->rx_queue);
- rte_free((*internals)->tx_queue);
- return -1;
+ goto free_internals;
}
for (q = 0; q < nb_queues; q++) {
@@ -664,20 +662,20 @@ struct pmd_internals {
PMD_LOG(ERR,
"%s: I/F name too long (%s)",
name, pair->value);
- return -1;
+ goto free_internals;
}
if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFINDEX)", name);
- return -1;
+ goto free_internals;
}
(*internals)->if_name = strdup(pair->value);
if ((*internals)->if_name == NULL)
- return -1;
+ goto free_internals;
(*internals)->if_index = ifr.ifr_ifindex;
if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) == -1) {
PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFHWADDR)", name);
- return -1;
+ goto free_internals;
}
memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
@@ -701,7 +699,7 @@ struct pmd_internals {
PMD_LOG_ERRNO(ERR,
"%s: could not open AF_PACKET socket",
name);
- return -1;
+ goto error;
}
tpver = TPACKET_V2;
@@ -854,6 +852,9 @@ struct pmd_internals {
((*internals)->rx_queue[q].sockfd != qsockfd))
close((*internals)->rx_queue[q].sockfd);
}
+free_internals:
+ rte_free((*internals)->rx_queue);
+ rte_free((*internals)->tx_queue);
free((*internals)->if_name);
rte_free(*internals);
return -1;
--
1.8.3.1
next prev parent reply other threads:[~2020-07-06 12:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-06 12:26 [dpdk-dev] [PATCH 0/3] fixes for af_packet driver wangyunjian
2020-07-06 12:27 ` [dpdk-dev] [PATCH 1/3] net/af_packet: fix check of file descriptors wangyunjian
2020-07-06 12:27 ` wangyunjian [this message]
2020-07-06 12:28 ` [dpdk-dev] [PATCH 3/3] net/af_packet: fix wrong munmap on init failure wangyunjian
2020-07-14 14:58 ` [dpdk-dev] [PATCH 0/3] fixes for af_packet driver Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e83ef7df3a4361264839a39f649e02d6606f11e5.1594037787.git.wangyunjian@huawei.com \
--to=wangyunjian@huawei.com \
--cc=dev@dpdk.org \
--cc=jerry.lilijun@huawei.com \
--cc=linville@tuxdriver.com \
--cc=stable@dpdk.org \
--cc=xudingke@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).