[libvirt] [PATCH] Make sure that filedescriptors are only closed once

Setting fd=-1 in these places makes sure that the fd is not closed twice later on in 'clean:'. This is of course a recipe for disaster in a multi-threaded system where the filedescriptor can belong to something else right away. At least we have a pattern... (looks like I can close the augeas bug as well...) Signed-off-by: Stefan Berger <stefanb@us.ibm.com> --- src/conf/domain_conf.c | 2 ++ src/conf/network_conf.c | 2 ++ src/conf/nwfilter_conf.c | 4 ++++ src/conf/storage_conf.c | 2 ++ 4 files changed, 10 insertions(+) Index: libvirt-acl/src/conf/domain_conf.c =================================================================== --- libvirt-acl.orig/src/conf/domain_conf.c +++ libvirt-acl/src/conf/domain_conf.c @@ -6805,6 +6805,8 @@ int virDomainSaveXML(const char *configD goto cleanup; } + fd = -1; + ret = 0; cleanup: if (fd != -1) Index: libvirt-acl/src/conf/network_conf.c =================================================================== --- libvirt-acl.orig/src/conf/network_conf.c +++ libvirt-acl/src/conf/network_conf.c @@ -694,6 +694,8 @@ int virNetworkSaveXML(const char *config goto cleanup; } + fd = -1; + ret = 0; cleanup: Index: libvirt-acl/src/conf/nwfilter_conf.c =================================================================== --- libvirt-acl.orig/src/conf/nwfilter_conf.c +++ libvirt-acl/src/conf/nwfilter_conf.c @@ -2200,6 +2200,8 @@ int virNWFilterSaveXML(const char *confi goto cleanup; } + fd = -1; + ret = 0; cleanup: @@ -2611,6 +2613,8 @@ virNWFilterPoolObjSaveDef(virNWFilterDri goto cleanup; } + fd = -1; + ret = 0; cleanup: Index: libvirt-acl/src/conf/storage_conf.c =================================================================== --- libvirt-acl.orig/src/conf/storage_conf.c +++ libvirt-acl/src/conf/storage_conf.c @@ -1567,6 +1567,8 @@ virStoragePoolObjSaveDef(virStorageDrive goto cleanup; } + fd = -1; + ret = 0; cleanup:

On Thu, Oct 14, 2010 at 09:20:01PM -0400, Stefan Berger wrote:
Setting fd=-1 in these places makes sure that the fd is not closed twice later on in 'clean:'. This is of course a recipe for disaster in a multi-threaded system where the filedescriptor can belong to something else right away. At least we have a pattern...
(looks like I can close the augeas bug as well...)
Hum, no, augeas library should make sure it never exits, whatever the conditions, that's still a bug IMHO. Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (2)
-
Daniel Veillard
-
Stefan Berger