]> git.ipfire.org Git - thirdparty/libvirt.git/commit
secret: Properly handle @def after virSecretObjAdd in driver
authorJohn Ferlan <jferlan@redhat.com>
Thu, 1 Jun 2017 12:17:52 +0000 (08:17 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 25 Jul 2017 13:15:30 +0000 (09:15 -0400)
commite4c0aff21514230f2f15aa5c7083219e1033f048
tree84fcca0c07efa30b6efb8b482911e6769fa71f00
parent7ca17da9f2f645398ea1315ce41b0a005651a02d
secret: Properly handle @def after virSecretObjAdd in driver

Since the virSecretObjListAdd technically consumes @def on success,
the secretDefineXML should set @def = NULL immediately and process
the remaining calls using a new @objDef variable. We can use use
VIR_STEAL_PTR since we know the Add function just stores @def in
obj->def.

Because we steal @def into @objDef, if we jump to restore_backup:
and @backup is set, then we need to ensure the @def would be
free'd properly, so we'll steal it back from @objDef. For the other
condition this fixes a double free of @def if the code had jumped to
@backup == NULL thus calling virSecretObjListRemove without setting
@def = NULL. In this case, the subsequent call to DefFree would
succeed and free @def; however, the call to EndAPI would also
call DefFree because the Unref done would be the last one for
the @obj meaning the obj->def would be used to call DefFree,
but it's already been free'd because @def wasn't managed right
within this error path.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/secret/secret_driver.c