From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id B67907F07 for ; Wed, 17 Dec 2014 13:56:52 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 17 Dec 2014 04:55:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,691,1406617200"; d="scan'208";a="500171243" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 17 Dec 2014 04:52:33 -0800 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id sBHCul5G001174; Wed, 17 Dec 2014 12:56:47 GMT Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id sBHCulZu016628; Wed, 17 Dec 2014 12:56:47 GMT Received: (from dtmrzglx@localhost) by sivswdev02.ir.intel.com with id sBHCulhS016624; Wed, 17 Dec 2014 12:56:47 GMT From: Daniel Mrzyglod To: dev@dpdk.org Date: Wed, 17 Dec 2014 12:56:36 +0000 Message-Id: <1418820996-16527-1-git-send-email-danielx.t.mrzyglod@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dpdk-dev] [PATCH] app/test lib/librte_pmd_af_packet: fix check for null & fix possible memory leak X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Dec 2014 12:56:53 -0000 app/test/test_sched.c: -Fix several checking for NULL pointer lib/librte_pmd_af_packet/rte_eth_af_packet.c: -Not munmaped queue area -Fix several checking for NULL pointer Signed-off-by: Daniel Mrzyglod --- app/test/test_sched.c | 2 ++ lib/librte_pmd_af_packet/rte_eth_af_packet.c | 49 ++++++++++++++++------------ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/app/test/test_sched.c b/app/test/test_sched.c index c957d80..9b6e037 100644 --- a/app/test/test_sched.c +++ b/app/test/test_sched.c @@ -166,6 +166,7 @@ test_sched(void) int err; mp = create_mempool(); + VERIFY(mp != NULL,"Error create mempool\n"); port_param.socket = 0; port_param.rate = (uint64_t) 10000 * 1000 * 1000 / 8; @@ -184,6 +185,7 @@ test_sched(void) for (i = 0; i < 10; i++) { in_mbufs[i] = rte_pktmbuf_alloc(mp); + VERIFY(in_mbufs[i] != NULL, "Bad packet allocation"); prepare_pkt(in_mbufs[i]); } 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..d9f1373 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; @@ -496,13 +501,13 @@ rte_pmd_init_internals(const char *name, RTE_LOG(ERR, PMD, "%s: I/F name too long (%s)\n", name, pair->value); - goto error; + goto error_free_queues; } if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) { RTE_LOG(ERR, PMD, "%s: ioctl failed (SIOCGIFINDEX)\n", name); - goto error; + goto error_free_queues; } (*internals)->if_index = ifr.ifr_ifindex; @@ -510,7 +515,7 @@ rte_pmd_init_internals(const char *name, RTE_LOG(ERR, PMD, "%s: ioctl failed (SIOCGIFHWADDR)\n", name); - goto error; + goto error_free_queues; } memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); @@ -544,7 +549,7 @@ rte_pmd_init_internals(const char *name, RTE_LOG(ERR, PMD, "%s: could not set PACKET_VERSION on AF_PACKET " "socket for %s\n", name, pair->value); - goto error; + goto error_free_queues; } discard = 1; @@ -554,7 +559,7 @@ rte_pmd_init_internals(const char *name, RTE_LOG(ERR, PMD, "%s: could not set PACKET_LOSS on " "AF_PACKET socket for %s\n", name, pair->value); - goto error; + goto error_free_queues; } #if defined(PACKET_QDISC_BYPASS) @@ -566,7 +571,7 @@ rte_pmd_init_internals(const char *name, "%s: could not set PACKET_QDISC_BYPASS " "on AF_PACKET socket for %s\n", name, pair->value); - goto error; + goto error_free_queues; } #endif @@ -575,7 +580,7 @@ rte_pmd_init_internals(const char *name, RTE_LOG(ERR, PMD, "%s: could not set PACKET_RX_RING on AF_PACKET " "socket for %s\n", name, pair->value); - goto error; + goto error_free_queues; } rc = setsockopt(qsockfd, SOL_PACKET, PACKET_TX_RING, req, sizeof(*req)); @@ -583,7 +588,7 @@ rte_pmd_init_internals(const char *name, RTE_LOG(ERR, PMD, "%s: could not set PACKET_TX_RING on AF_PACKET " "socket for %s\n", name, pair->value); - goto error; + goto error_free_queues; } rx_queue = &((*internals)->rx_queue[q]); @@ -596,13 +601,15 @@ rte_pmd_init_internals(const char *name, RTE_LOG(ERR, PMD, "%s: call to mmap failed on AF_PACKET socket for %s\n", name, pair->value); - goto error; + goto error_free_queues; } /* rdsize is same for both Tx and Rx */ rdsize = req->tp_frame_nr * sizeof(*(rx_queue->rd)); rx_queue->rd = rte_zmalloc_socket(name, rdsize, 0, numa_node); + if (rx_queue->rd == NULL) + goto error_free_queues; for (i = 0; i < req->tp_frame_nr; ++i) { rx_queue->rd[i].iov_base = rx_queue->map + (i * framesize); rx_queue->rd[i].iov_len = req->tp_frame_size; @@ -615,6 +622,8 @@ rte_pmd_init_internals(const char *name, tx_queue->map = rx_queue->map + req->tp_block_size * req->tp_block_nr; tx_queue->rd = rte_zmalloc_socket(name, rdsize, 0, numa_node); + if (tx_queue->rd == NULL) + goto error_free_queues; for (i = 0; i < req->tp_frame_nr; ++i) { tx_queue->rd[i].iov_base = tx_queue->map + (i * framesize); tx_queue->rd[i].iov_len = req->tp_frame_size; @@ -671,19 +680,19 @@ rte_pmd_init_internals(const char *name, return 0; -error: - if (data) - rte_free(data); - if (pci_dev) - rte_free(pci_dev); +error_free_queues: + if (*internals == NULL) + return -1; 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); + munmap((*internals)->rx_queue[q].map, + 2 * req->tp_block_size * req->tp_block_nr); + rte_free((*internals)->rx_queue[q].rd); + rte_free((*internals)->tx_queue[q].rd); } - if (*internals) - rte_free(*internals); +error: + rte_free(data); + rte_free(pci_dev); + rte_free(*internals); return -1; } -- 2.1.0