From: Martin Willi Date: Wed, 6 May 2009 09:09:57 +0000 (+0200) Subject: fixed remove_child_cfg(), use correct enumerator for remove_at X-Git-Url: https://git.strongswan.org/?p=strongswan.git;a=commitdiff_plain;h=5bbfd264ec7580f21cd50ecc3f07c31d1d530939;hp=94ffefc40c7d8f0da7c1c3468576ac651923ea7d;ds=sidebyside fixed remove_child_cfg(), use correct enumerator for remove_at --- diff --git a/src/charon/config/peer_cfg.c b/src/charon/config/peer_cfg.c index c543331..da796d6 100644 --- a/src/charon/config/peer_cfg.c +++ b/src/charon/config/peer_cfg.c @@ -198,13 +198,39 @@ static void add_child_cfg(private_peer_cfg_t *this, child_cfg_t *child_cfg) } /** + * child_cfg enumerator + */ +typedef struct { + enumerator_t public; + enumerator_t *wrapped; + mutex_t *mutex; +} child_cfg_enumerator_t; + +/** * Implementation of peer_cfg_t.remove_child_cfg. */ -static void remove_child_cfg(private_peer_cfg_t *this, enumerator_t *enumerator) +static void remove_child_cfg(private_peer_cfg_t *this, + child_cfg_enumerator_t *enumerator) +{ + this->child_cfgs->remove_at(this->child_cfgs, enumerator->wrapped); +} + +/** + * Implementation of child_cfg_enumerator_t.destroy + */ +static void child_cfg_enumerator_destroy(child_cfg_enumerator_t *this) { - this->mutex->lock(this->mutex); - this->child_cfgs->remove_at(this->child_cfgs, enumerator); this->mutex->unlock(this->mutex); + this->wrapped->destroy(this->wrapped); + free(this); +} + +/** + * Implementation of child_cfg_enumerator_t.enumerate + */ +static bool child_cfg_enumerate(child_cfg_enumerator_t *this, child_cfg_t **chd) +{ + return this->wrapped->enumerate(this->wrapped, chd); } /** @@ -212,12 +238,15 @@ static void remove_child_cfg(private_peer_cfg_t *this, enumerator_t *enumerator) */ static enumerator_t* create_child_cfg_enumerator(private_peer_cfg_t *this) { - enumerator_t *enumerator; - + child_cfg_enumerator_t *enumerator = malloc_thing(child_cfg_enumerator_t); + + enumerator->public.enumerate = (void*)child_cfg_enumerate; + enumerator->public.destroy = (void*)child_cfg_enumerator_destroy; + enumerator->mutex = this->mutex; + enumerator->wrapped = this->child_cfgs->create_enumerator(this->child_cfgs); + this->mutex->lock(this->mutex); - enumerator = this->child_cfgs->create_enumerator(this->child_cfgs); - return enumerator_create_cleaner(enumerator, - (void*)this->mutex->unlock, this->mutex); + return &enumerator->public; } /**