<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div>Hi. I am using libvirt for some time and I have found the following problem.<br></div>When I try opening two connections with the same credentials to the same host but using different transport(TCP and TLS) I get the following error when trying to free the TLS one:<br>
"*** Error in `./test': double free or corruption (!prev): 0x00000000014a7a60 ***<br>Aborted (core dumped)"<br><br></div>Example code:<br>#include <stdio.h><br>#include <stdlib.h><br>#include <string.h><br>
#include <libvirt/libvirt.h><br><br><br>struct CredentialsPack {<br> const char* username;<br> const char* password;<br>};<br><br>struct CredentialsPack* newCredentialsPack(const char* username,<br> const char* password) {<br>
struct CredentialsPack* ptr = malloc(sizeof(struct CredentialsPack));<br> ptr->username = username;<br> ptr->password = password;<br> return ptr;<br>}<br><br>static int authCredTypes[] = { VIR_CRED_AUTHNAME, VIR_CRED_PASSPHRASE, };<br>
<br>static int authCb(virConnectCredentialPtr cred, unsigned int ncred,<br> void* cbdata) {<br> struct CredentialsPack* inputCreds = (struct CredentialsPack*) cbdata;<br> int i;<br> for (i = 0; i < ncred; ++i) {<br>
if (cred[i].type == VIR_CRED_AUTHNAME) {<br> cred[i].result = strdup(inputCreds->username);<br> if (cred[i].result == NULL) {<br> return -1;<br> }<br> cred[i].resultlen = strlen(cred[i].result);<br>
} else if (cred[i].type == VIR_CRED_PASSPHRASE) {<br> cred[i].result = strdup(inputCreds->password);<br> if (cred[i].result == NULL) {<br> return -1;<br> }<br> cred[i].resultlen = strlen(cred[i].result);<br>
}<br> }<br> return 0;<br>}<br><br></div>int main(){<br> struct CredentialsPack* credentials = newCredentialsPack("user", "pass");<br> virConnectAuth auth;<br> auth.credtype = authCredTypes;<br>
auth.ncredtype = sizeof(authCredTypes) / sizeof(int);<br> auth.cb = authCb;<br> auth.cbdata = credentials;<br><br> virConnectPtr conn;<br> conn = virConnectOpenAuth("qemu+tcp://host1/system", &auth, 0);<br>
<br><br> struct CredentialsPack* credentials2 = newCredentialsPack("user", "pass");<br> virConnectAuth auth2;<br> auth2.credtype = authCredTypes;<br> auth2.ncredtype = sizeof(authCredTypes) / sizeof(int);<br>
auth2.cb = authCb;<br> auth2.cbdata = credentials2;<br><br> virConnectPtr conn2;<br> conn2 = virConnectOpenAuth("qemu://host1/system", &auth2, 0);<br><br>// virConnectClose(conn); // this does not change the behaviour<br>
virConnectClose(conn2); // here the error occurs<br>
}<br><br></div>If I try to close "conn" then everything works until I try to close "conn2". I can even invoke virConnectListAllDomains using "conn2" and use the domain pointers when "conn" is closed. The problem is when I try to close "conn2".<br>
<br></div>The platform running this code is Ubuntu 14.04. The version of libvirt is 1.2.2 (default configuration). The certificate of the CA which signed the server certificate is under /etc/pki/CA/cacert.pem<br><br></div>
The target machine is RHEL 6.5. The version of libvirt is 0.10.2. It is configured this way:<br></div>listen_tls = 1<br></div>listen_tcp = 1<br></div>auth_tcp = sasl<br>auth_tls = sasl<br></div>tls_no_verify_certificate = 1<br>
</div>Everything else is set to default.<br>
</div><div>The certificate of the CA which signed the server certificate is under /etc/pki/CA/cacert.pem</div>The user "user" is added to the DB( using $ saslpasswd2 -a libvirt user). I can successfully execute the following on the command line using the "user"/"pass" credentials:<br>
virsh -c qemu://host1/system list<br>virsh -c qemu+tcp://host1/system list<br><br></div><div>I hope this will be useful.<br></div><div>Thank you.<br></div></div>