提交 dc4e9bfb 编写于 作者: A Adrian Brzezinski 提交者: Daniel P. Berrangé

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: NDaniel P. Berrangé <berrange@redhat.com>
Signed-off-by: NAdrian Brzezinski <redhat@adrb.pl>
上级 c2568c1c
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册