Add a temporary helper to search for a specific secret by address on the list and remove it if it's found. The following patch will introduce a common allocation and listInsert helper. That means error paths of the routines calling would need a way to remove the secret off the list. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/secret/secret_driver.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index f1ab58c..70bd2f3 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -353,6 +353,26 @@ secretLoadValue(virSecretObjPtr secret) return ret; } + +static void +listUnlinkSecret(virSecretObjPtr *pptr, + virSecretObjPtr secret) +{ + if (!secret) + return; + + if (*pptr == secret) { + *pptr = secret->next; + } else { + virSecretObjPtr tmp = *pptr; + while (tmp && tmp->next != secret) + tmp = tmp->next; + if (tmp) + tmp->next = secret->next; + } +} + + static virSecretObjPtr secretLoad(const char *file, const char *path, @@ -978,15 +998,7 @@ secretUndefine(virSecretPtr obj) secretDeleteSaved(secret) < 0) goto cleanup; - if (driver->secrets == secret) { - driver->secrets = secret->next; - } else { - virSecretObjPtr tmp = driver->secrets; - while (tmp && tmp->next != secret) - tmp = tmp->next; - if (tmp) - tmp->next = secret->next; - } + listUnlinkSecret(&driver->secrets, secret); secretFree(secret); ret = 0; -- 2.5.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list