bind/2879-expand-the-pool-then-copy-over-the-old-entries-so-we.patch
songnannan e152f570a8 init
2019-12-28 09:41:34 +08:00

50 lines
1.4 KiB
Diff

From afde30fe9b1fd43595290a6763db6d52e0903c5a Mon Sep 17 00:00:00 2001
From: Mark Andrews <marka@isc.org>
Date: Fri, 19 Oct 2018 19:36:17 +1100
Subject: [PATCH 2879/3677] expand the pool then copy over the old entries so
we that failures do not break the old pool; also don't leak the new pool on
error
---
lib/isc/pool.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/lib/isc/pool.c b/lib/isc/pool.c
index 5c693a6..8fb2a45 100644
--- a/lib/isc/pool.c
+++ b/lib/isc/pool.c
@@ -131,21 +131,22 @@ isc_pool_expand(isc_pool_t **sourcep, unsigned int count,
newpool->init = pool->init;
newpool->initarg = pool->initarg;
- /* Copy over the objects from the old pool */
- for (i = 0; i < pool->count; i++) {
- newpool->pool[i] = pool->pool[i];
- pool->pool[i] = NULL;
- }
-
/* Populate the new entries */
for (i = pool->count; i < count; i++) {
- result = pool->init(&newpool->pool[i], pool->initarg);
+ result = newpool->init(&newpool->pool[i],
+ newpool->initarg);
if (result != ISC_R_SUCCESS) {
- isc_pool_destroy(&pool);
+ isc_pool_destroy(&newpool);
return (result);
}
}
+ /* Copy over the objects from the old pool */
+ for (i = 0; i < pool->count; i++) {
+ newpool->pool[i] = pool->pool[i];
+ pool->pool[i] = NULL;
+ }
+
isc_pool_destroy(&pool);
pool = newpool;
}
--
1.8.3.1