Re: [PATCH kvm-unit-tests 2/4] Introduce a C++ wrapper for the kvm APIs

Avi Kivity
2010-11-25T16:32:13Z

On 11/24/2010 04:29 PM, Avi Kivity wrote:
>>> +kvm_msrs* vcpu::alloc_msr_list(size_t nmsrs)
>>> +{
>>> + size_t size = sizeof(kvm_msrs) + sizeof(kvm_msr_entry) * nmsrs;
>>> + kvm_msrs* ret = static_cast<kvm_msrs*>(malloc(size));
>>> + if (!ret) {
>>> + throw ENOMEM;
>>> + }
>>> + return ret;
>>> +}
>>
>> malloc?
>>
>> Mixing C and C++ allocations is nasty stuff. Would be nicer to new
>> an object and return it such that delete can be used consistently.
>
> 5 years of C.

It has to be a malloc() in fact. We're allocating a variable size
object that is not an array. You're right that we can't give it to an
auto_ptr<> though, since that uses delete.

--
error compiling committee.c: too many arguments to function