mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
rpc: cleanup in virNetTLSContextNew
Failed new gnutls context allocations in virNetTLSContextNew function results in double free and segfault. Occasional memory leaks may also occur. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Adrian Brzezinski <redhat@adrb.pl>
This commit is contained in:
parent
c2568c1c5e
commit
dc4e9bfb84
@ -707,6 +707,13 @@ static virNetTLSContextPtr virNetTLSContextNew(const char *cacert,
|
||||
|
||||
err = gnutls_certificate_allocate_credentials(&ctxt->x509cred);
|
||||
if (err) {
|
||||
/* While gnutls_certificate_credentials_t will free any
|
||||
* partially allocated credentials struct, it does not
|
||||
* set the returned pointer back to NULL after it is
|
||||
* freed in an error path.
|
||||
*/
|
||||
ctxt->x509cred = NULL;
|
||||
|
||||
virReportError(VIR_ERR_SYSTEM_ERROR,
|
||||
_("Unable to allocate x509 credentials: %s"),
|
||||
gnutls_strerror(err));
|
||||
@ -758,7 +765,9 @@ static virNetTLSContextPtr virNetTLSContextNew(const char *cacert,
|
||||
error:
|
||||
if (isServer)
|
||||
gnutls_dh_params_deinit(ctxt->dhParams);
|
||||
gnutls_certificate_free_credentials(ctxt->x509cred);
|
||||
if (ctxt->x509cred)
|
||||
gnutls_certificate_free_credentials(ctxt->x509cred);
|
||||
VIR_FREE(ctxt->priority);
|
||||
VIR_FREE(ctxt);
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user