[libvirt] [PATCH 3/4] rpc: avoid memory leak on error
Eric Blake
eblake at redhat.com
Fri Jul 1 22:54:12 UTC 2011
On 06/30/2011 07:05 PM, Wen Congyang wrote:
> At 07/01/2011 07:36 AM, Eric Blake Write:
>> Detected by Coverity. The leak is on an error path, but I'm not
>> sure whether that path is likely to be triggered in practice.
>>
>> error:
>> virNetSocketFree(clientsock);
>> + virNetServerClientFree(client);
>
> If svc->dispatchFunc is NULL, we will goto here to do cleanup. Unfortunately,
> client->sock is clientsock and it will be freed again in virNetServerClientFree().
> It may cause libvirtd crashed.
>
> If svc->dispatchFunc() failed, we close and free client. But we only free client here,
> not close it here. Do we need to close it here?
>
> I think the cleanup code should like this:
>
> if (client) {
> virNetServerClientClose(client);
> virNetServerClientFree(client);
> } else {
> virNetSocketFree(clientsock);
> }
Makes sense to me, but I'd rather hear Dan's take on it as author of
that code.
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110701/b443ac61/attachment-0001.sig>
More information about the libvir-list
mailing list