SHA256
1
0
forked from pool/dpdk
dpdk/0024-mempool-fix-leak-when-creation-fails.patch
Nirmoy Das d761fec5f6 Accepting request 399089 from home:ndas:branches:network
- Applied all the fixes recommended by upstream for 
  v2.2 stable release(bsc#981996).
	[+0008-app-testpmd-handle-SIGINT-and-SIGTERM.patch,
	+0009-bonding-copy-entire-config-structure-in-mode-4.patch,
	+0010-bonding-fix-active-slaves-with-no-primary.patch,
	+0011-bonding-do-not-ignore-multicast-in-mode-4.patch,
	+0012-bonding-do-not-activate-slave-twice.patch,
	+0013-bonding-fix-crash-when-no-slave-device.patch,
	+0014-bonding-fix-detach-of-bonded-device.patch,
	+0015-bonding-fix-detach-of-slave-devices.patch,
	+0016-eal-linux-support-built-in-kernel-modules.patch,
	+0017-examples-l3fwd-handle-SIGINT-and-SIGTERM.patch,
	+0018-fm10k-fix-VLAN-flag-in-scattered-Rx.patch,
	+0019-i40e-base-fix-driver-load-failure.patch,
	+0020-i40e-base-fix-missing-check-for-stopped-admin-queue.patch,
	+0021-i40e-fix-inverted-check-for-no-refcount.patch,
	+0022-i40e-fix-overflow.patch,
	+0023-i40e-fix-VLAN-filtering.patch,
	+0024-mempool-fix-leak-when-creation-fails.patch,
	+0025-pcap-fix-captured-frame-length.patch,
	+0026-port-fix-crash-for-ethdev-writer-nodrop.patch,
	+0027-port-fix-crash-for-ring-writer-nodrop.patch,
	+0028-tools-fix-unbinding-failure-handling.patch,
	+0029-tools-support-Python-3-in-bind-script.patch,
	+0030-tools-support-binding-to-built-in-kernel-modules.patch,
	+0031-vhost-fix-leak-of-fds-and-mmaps.patch,
	+0032-virtio-fix-crash-in-statistics-functions.patch,
	+0033-virtio-fix-descriptors-pointing-to-the-same-buffer.patch,
	+0034-virtio-fix-restart.patch]

OBS-URL: https://build.opensuse.org/request/show/399089
OBS-URL: https://build.opensuse.org/package/show/network/dpdk?expand=0&rev=3
2016-05-31 11:30:42 +00:00

90 lines
2.8 KiB
Diff

From 86f36ff9578b5f3d697c8fcf6072dcb70e2b246f Mon Sep 17 00:00:00 2001
From: Olivier Matz <olivier.matz@6wind.com>
Date: Tue, 16 Feb 2016 15:40:10 +0100
Subject: [PATCH] mempool: fix leak when creation fails
Since commits ff909fe21f and 4e32101f9b, it is now possible to free
memzones and rings.
The rte_mempool_create() should be modified to take advantage of this
and not leak memory when an allocation fails.
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
lib/librte_mempool/rte_mempool.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index aff5f6d..f8781e1 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -438,8 +438,8 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
char rg_name[RTE_RING_NAMESIZE];
struct rte_mempool_list *mempool_list;
struct rte_mempool *mp = NULL;
- struct rte_tailq_entry *te;
- struct rte_ring *r;
+ struct rte_tailq_entry *te = NULL;
+ struct rte_ring *r = NULL;
const struct rte_memzone *mz;
size_t mempool_size;
int mz_flags = RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY;
@@ -511,7 +511,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
snprintf(rg_name, sizeof(rg_name), RTE_MEMPOOL_MZ_FORMAT, name);
r = rte_ring_create(rg_name, rte_align32pow2(n+1), socket_id, rg_flags);
if (r == NULL)
- goto exit;
+ goto exit_unlock;
/*
* reserve a memory zone for this mempool: private data is
@@ -536,7 +536,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
te = rte_zmalloc("MEMPOOL_TAILQ_ENTRY", sizeof(*te), 0);
if (te == NULL) {
RTE_LOG(ERR, MEMPOOL, "Cannot allocate tailq entry!\n");
- goto exit;
+ goto exit_unlock;
}
/*
@@ -561,15 +561,8 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
snprintf(mz_name, sizeof(mz_name), RTE_MEMPOOL_MZ_FORMAT, name);
mz = rte_memzone_reserve(mz_name, mempool_size, socket_id, mz_flags);
-
- /*
- * no more memory: in this case we loose previously reserved
- * space for the ring as we cannot free it
- */
- if (mz == NULL) {
- rte_free(te);
- goto exit;
- }
+ if (mz == NULL)
+ goto exit_unlock;
if (rte_eal_has_hugepages()) {
startaddr = (void*)mz->addr;
@@ -633,11 +626,16 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
TAILQ_INSERT_TAIL(mempool_list, te, next);
rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
-
-exit:
rte_rwlock_write_unlock(RTE_EAL_MEMPOOL_RWLOCK);
return mp;
+
+exit_unlock:
+ rte_rwlock_write_unlock(RTE_EAL_MEMPOOL_RWLOCK);
+ rte_ring_free(r);
+ rte_free(te);
+
+ return NULL;
}
/* Return the number of entries in the mempool */
--
2.6.2