From 8818376889bcd86e2b2efd336e97627f1bc4710f Mon Sep 17 00:00:00 2001 From: Jim Fehlig Date: Wed, 4 Sep 2013 15:58:27 -0600 Subject: [PATCH] Don't call regfree() if regcomp() fails POSIX states that the preg parameter to regcomp() is undefined on failure, so no need to call regfree() in these cases. http://pubs.opengroup.org/onlinepubs/009695399/functions/regcomp.html See also a discussion on the libvirt dev list https://www.redhat.com/archives/libvir-list/2013-September/msg00262.html --- src/storage/storage_backend.c | 2 +- src/storage/storage_backend_logical.c | 1 - src/xen/xen_hypervisor.c | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index ed893f0141..b7edf85950 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -1579,7 +1579,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, regerror(err, ®[i], error, sizeof(error)); virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to compile regex %s"), error); - for (j = 0; j <= i; j++) + for (j = 0; j < i; j++) regfree(®[j]); VIR_FREE(reg); return -1; diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 8998a11b92..0b146793e8 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -195,7 +195,6 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, if (err != 0) { char error[100]; regerror(err, reg, error, sizeof(error)); - regfree(reg); virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to compile regex %s"), error); diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index cd85b75fee..f9c7b4083f 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -1787,7 +1787,6 @@ xenHypervisorInit(struct xenHypervisorVersions *override_versions) if (errcode != 0) { char error[100]; regerror(errcode, &flags_hvm_rec, error, sizeof(error)); - regfree(&flags_hvm_rec); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", error); return -1; } @@ -1795,7 +1794,6 @@ xenHypervisorInit(struct xenHypervisorVersions *override_versions) if (errcode != 0) { char error[100]; regerror(errcode, &flags_pae_rec, error, sizeof(error)); - regfree(&flags_pae_rec); regfree(&flags_hvm_rec); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", error); return -1; @@ -1804,7 +1802,6 @@ xenHypervisorInit(struct xenHypervisorVersions *override_versions) if (errcode != 0) { char error[100]; regerror(errcode, &xen_cap_rec, error, sizeof(error)); - regfree(&xen_cap_rec); regfree(&flags_pae_rec); regfree(&flags_hvm_rec); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", error);