[PATCH 1/2] Don't call regfree() if regcomp() fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx>
---
 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 4ebe11b..bbdda19 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -1579,7 +1579,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
             regerror(err, &reg[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(&reg[j]);
             VIR_FREE(reg);
             return -1;
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 8998a11..0b14679 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 cd85b75..f9c7b40 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);
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]