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
This commit is contained in:
Jim Fehlig 2013-09-04 15:58:27 -06:00
parent 12509c7999
commit 8818376889
3 changed files with 1 additions and 5 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);