diff mbox

[dpdk-dev,1/3] af_packet: ensure *internals is not null when dereferencing

Message ID 1418747424-22254-2-git-send-email-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Bruce Richardson Dec. 16, 2014, 4:30 p.m. UTC
The cleanup code on error checks for *internals being NULL only after
using the pointer to perform other cleanup. Fix this by moving the
clean-up based on the pointer inside the check for NULL.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff mbox

Patch

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 d0fb3eb..ad7242c 100644
--- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
+++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
@@ -676,14 +676,15 @@  error:
 		rte_free(data);
 	if (pci_dev)
 		rte_free(pci_dev);
-	for (q = 0; q < nb_queues; q++) {
-		if ((*internals)->rx_queue[q].rd)
-			rte_free((*internals)->rx_queue[q].rd);
-		if ((*internals)->tx_queue[q].rd)
-			rte_free((*internals)->tx_queue[q].rd);
-	}
-	if (*internals)
+	if (*internals) {
+		for (q = 0; q < nb_queues; q++) {
+			if ((*internals)->rx_queue[q].rd)
+				rte_free((*internals)->rx_queue[q].rd);
+			if ((*internals)->tx_queue[q].rd)
+				rte_free((*internals)->tx_queue[q].rd);
+		}
 		rte_free(*internals);
+	}
 	return -1;
 }